【发布时间】:2012-04-29 20:01:05
【问题描述】:
我正在尝试向 UINavigationController 的导航栏添加 2 个按钮:
1) 左侧的标准“后退”按钮 - 有效,并且
2) 右侧的“搜索”按钮 - 不显示。
代码如下:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// 1st button - this shows up correctly:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
backButton.title = @"MAIN";
self.navigationItem.backBarButtonItem = backButton;
// 2nd. button - this one does not show up:
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
target:self
action:@selector(goSearching:)];
self.navigationItem.rightBarButtonItem = searchButton;
itemsByTitleVC *itemsView = [[itemsByTitleVC alloc] initWithNibName:@"itemsByTitleVC" bundle:nil];
[self.navigationController pushViewController:itemsView animated:YES];
}
有人知道为什么这不起作用吗? (对于它的价值,我使用的是 Xcode 4.2,带有 Storyboard...)
【问题讨论】:
-
按下 ViewController 后设置第二个按钮或在特定 itemsByTitleVC 控制器中设置第二个按钮
-
都没有用。我之前尝试在正在推送的 viewController 的 viewDidLoad 中添加 rightBarButtonItem - 没有用...
标签: iphone uinavigationcontroller uinavigationitem rightbarbuttonitem