简体   繁体   English

UINavigationController工具栏按钮

[英]UINavigationController Toolbar Buttons

I have a UINavigationController that I've set as the rootViewController of my window. 我有一个UINavigationController我已经设置为我的窗口的rootViewController。 In the NIB file I've set it up so that it has a "Bottom Bar" of "Toolbar". 在NIB文件中,我已将其设置为具有“工具栏”的“底栏”。 In Interface Builder I've added a UIBarButtonItem. 在Interface Builder中,我添加了一个UIBarButtonItem。 This all works great and I can handle the button click fine. 这一切都很好,我可以处理按钮单击罚款。 When I hit one of the buttons, I push a new view onto the ViewController and that works fine too. 当我点击其中一个按钮时,我将一个新视图推送到ViewController上,这也很好用。 One problem, my button disappears when the view is loaded. 一个问题,我的按钮在加载视图时消失。 Now in the subsequent view I can set the bottom bar to be a Toolbar and I see it in Interface Builder, but I cannot add any buttons to it. 现在在后续视图中我可以将底栏设置为工具栏,我在Interface Builder中看到它,但我无法添加任何按钮。

I know I'm either missing something obvious or thinking about this incorrectly but how do I add UIBarButtonItems to subsequent views pushed to my nav controller? 我知道我要么错过了一些明显的东西,要么想错了但是如何将UIBarButtonItems添加到推送到导航控制器的后续视图中? I'm talking the bar at the bottom, not the nav bar at the top. 我说的是底部的栏,而不是顶部的导航栏。

Any ideas? 有任何想法吗?

The toolbarItems property on the UIViewController is what you are interested in. You can create UIBarButtonItems programmatically and add them to a new toolBarItems array in viewDidLoad. 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]];
}

This worked better for me: 这对我来说效果更好:

[[self navigationItem] setLeftBarButtonItem:homeButton];

You can do the same for the right side. 您可以在右侧执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM