ios 您可以通过故事板向导航栏添加按钮吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9273204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can you add buttons to navigation bars through storyboard?
提问by sapi
At the moment, I've been adding navigation buttons like follows:
目前,我一直在添加如下导航按钮:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Add"
style:self.editButtonItem.style
target:self
action:@selector(doneButtonPressed)];
It seems a bit silly to not add them through storyboard, but I can't find a way to do so. Is there one that I'm missing?
不通过故事板添加它们似乎有点愚蠢,但我找不到这样做的方法。有没有我失踪的?
回答by rob mayoff
You can just drag out a Bar Button Item and drop it on the right end of the view controller's navigation bar:
您可以拖出一个 Bar Button Item 并将其放在视图控制器导航栏的右端:
回答by Ken Toh
As of Xcode 6, it looks like the navigation item on the navigation bar is no longer created automatically.
从 Xcode 6 开始,导航栏上的导航项似乎不再自动创建。
You'll need to drag out a Navigation Item onto the navigation bar first before you can drag out a Bar Button Item (as detailed in Rob's answer) to add to the navigation item.
您需要先将导航项拖到导航栏上,然后才能拖出栏按钮项(如 Rob 的回答中所述)以添加到导航项。