我有一个UINavigationController,我已将其设置为窗口的rootViewController。在NIB文件中,我已将其设置为具有“工具栏”的“底栏”。在Interface Builder中,我添加了一个UIBarButtonItem。这一切都很好,我可以处理按钮单击罚款。当我点击其中一个按钮时,我将一个新视图推送到ViewController上,这也很好用。一个问题,我的按钮在加载视图时消失。现在在后续视图中,我可以将底栏设置为工具栏,我在Interface Builder中看到它,但我无法添加任何按钮。
我知道我要么错过了一些明显的东西,要么想错了但是如何将UIBarButtonItems添加到推送到导航控制器的后续视图中?我说的是底部的栏,而不是顶部的导航栏。
有什么想法吗?
答案 0 :(得分:11)
UIViewController上的toolbarItems属性是您感兴趣的。您可以以编程方式创建UIBarButtonItems并将它们添加到viewDidLoad中的新toolBarItems数组中。
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem* editButton = [[[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(editAction)] autorelease];
[self setToolbarItems:[NSArray arrayWithObject:editButton]];
}
答案 1 :(得分:-2)
这对我来说效果更好:
[[self navigationItem] setLeftBarButtonItem:homeButton];
你可以在右侧做同样的事情。