所以我有一个带 TableView 的 Root View 。我这样显示工具栏:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationController.toolbarHidden = NO;
}
然后我实现了 setToolbarItems 方法:
- (void)setToolbarItems:(NSArray *)toolbarItems animated:(BOOL)animated
{
UIBarButtonItem *buttonItem;
buttonItem = [[UIBarButtonItem alloc] initWithTitle:@"Hello" style:UIBarButtonItemStyleDone target:self action:@selector(goBack:)];
self.navigationController.toolbarItems = [ NSArray arrayWithObject: buttonItem ];
}
结果是一个空的工具栏。为什么?
最佳答案
来自文档:
toolbarItems The toolbar items associated with the view controller.
@property(nonatomic, retain) NSArray *toolbarItems Discussion This property contains an array of UIBarButtonItem objects and works in >conjunction with a UINavigationController object. If this view controller is >embedded inside a navigation controller interface, and the navigation >controller displays a toolbar, this property identifies the items to display in >that toolbar.
You can set the value of this property explicitly or use the >setToolbarItems:animated: method to animate changes to the visible set of >toolbar items.
换句话说,尝试通过实际的 View Controller 访问它,而不是像这样的导航 Controller :
self.toolbarItems = [ NSArray arrayWithObject: buttonItem ];
关于iphone - 无法将按钮添加到 TableView 工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10059442/