xcode 如何在界面构建器中添加条形按钮项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5336468/
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
How to add a bar button item in interface builder?
提问by Upvote
I am really new to iPhone development and I need help setting up my views.
我对 iPhone 开发真的很陌生,我需要帮助来设置我的观点。
I have a view that is named FirstViewController.xib
and a controller class for this view.
我有一个已命名的视图FirstViewController.xib
和该视图的控制器类。
In my MainWindox.xib
I have setup a root controller with a moveToNextView
function that is connected to the options bar button item.
在我中,MainWindox.xib
我设置了一个根控制器,其moveToNextView
功能连接到选项栏按钮项。
So when I click on this item the current view switches to the first view and I am able to swticht back. That works fine so far.
因此,当我单击此项目时,当前视图会切换到第一个视图,并且我可以切换回来。到目前为止效果很好。
The navigation bar at the top of the screen from the MainWindow.xib
is displayed in the first view, too. But when I open FirstViewController.xib
there isn't any navigation bar defined (but on build&run it is displayed).
屏幕顶部的导航栏MainWindow.xib
也显示在第一个视图中。但是当我打开时FirstViewController.xib
没有定义任何导航栏(但在构建和运行时会显示)。
This is a problem for me because I want to add a save bar item to the first view. How do I solve that?
这对我来说是个问题,因为我想在第一个视图中添加一个保存栏项目。我该如何解决?
采纳答案by Lukman
You have to do it from code. Add to your FirstViewController class viewDidLoad
method:
你必须从代码中做到这一点。添加到您的 FirstViewController 类viewDidLoad
方法:
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStyleDone target:self action:@selector(doSave:)];
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
回答by anders
Assuming you have a UIViewController (or UIViewController subclass) that is a child of a UINavigationController. Note, I'm using storyboards so your results may vary when using xibs.
假设您有一个 UIViewController(或 UIViewController 子类),它是 UINavigationController 的子类。请注意,我使用的是故事板,因此在使用 xibs 时您的结果可能会有所不同。
If you do not see a UINavigationBar on the interface, try manually changing the simulated metrics.
Drag a Navigation Item onto the view (anywhere). You should now have a place to enter the title in the interface builder.
如果您在界面上没有看到 UINavigationBar,请尝试手动更改模拟指标。
将导航项拖到视图上(任何地方)。您现在应该有一个地方可以在界面构建器中输入标题。
- Now you can drag Bar Button Items onto the nav bar.
- 现在您可以将 Bar Button Items 拖到导航栏上。
回答by moliveira
Just drag a bar button item onto your nav bar in Interface Builder. Xcode automatically wires it up then you can use it like anything else...
只需将一个栏按钮项拖到 Interface Builder 中的导航栏上即可。Xcode 自动连接它然后你可以像其他任何东西一样使用它......