【发布时间】:2011-01-29 08:06:27
【问题描述】:
我有一个 UINavigationController,里面有一个 UITableViewController。我想在底部显示一个带有 UIBarButtonItem 的 ToolBar。工具栏出现了,但按钮不会出现。有谁知道为什么?
- (void)viewDidLoad {
[super viewDidLoad];
[[self navigationItem] setTitle:@"Selections List"];
[[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addProjectSearch:)] autorelease]];
[[self navigationItem] setLeftBarButtonItem:[self editButtonItem]];
[[super tableView] setDataSource: self];
[[super tableView] setDelegate: self];
//Toolbar
UIBarButtonItem * logoutButton = [[[UIBarButtonItem alloc] initWithTitle:@"Log out" style:UIBarButtonItemStylePlain target:self action:@selector(logOut:)]autorelease];
NSMutableArray * arr = [NSMutableArray arrayWithObjects:logoutButton, nil];
[[self navigationController] setToolbarHidden: NO animated:YES];
[[self navigationController] setToolbarItems:arr animated:YES];
}
【问题讨论】:
-
我遇到了这个确切的问题,并且没有一个建议的解决方案对我有用。也许有人可以评论哪些事情会出错以及哪些事情会阻止工作。具体来说:Tom 的 VC 设置,Olivier 的 in-viewDidAppear 不起作用。 FWIW,我的工具栏出现,但没有按钮。 (是的,我调用了 setToolbarItems:!)
-
编辑/跟进:我的错误。重新阅读 Tom's & Olivier 的答案并更仔细地应用他们的建议让我启动并运行。对两者都 +1。
标签: iphone objective-c cocoa-touch uikit uitoolbar