在界面生成器中添加 UIBarButtonItem,如何?
我有一个基于导航的应用程序,它有一个包含 uitableviewcontrollers 的 uinavigataioncontroller 。我想向 uinavigataioncontroller 的 UINavigationbar 添加按钮,通常我编写代码来添加这些按钮,如下所示:
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveClicked:)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];
我现在的想法是使用界面生成器。但我不知道该怎么做。我想做的是在视图控制器的 xib 文件中添加一个 UINavigationItem (我的视图控制器称为 TextViewController),如下所示:
请参阅此图片: http://i48.tinypic.com/qq5yk7.jpg
但是如何让 TextViewController 使用我添加的 UINavigationItem 呢?我添加的按钮未显示在导航栏中。
关于如何做到这一点有什么想法吗?我缺少什么?
I have a navigation based application that have a uinavigataioncontroller containing uitableviewcontrollers. I want to add buttons to the UINavigationbar of the uinavigataioncontroller, usually I write code to add these buttons, something like this:
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveClicked:)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];
My idea now was to use interface builder instead. But I'm not sure how to do it. What I'm trying to do is to add a UINavigationItem in the xib file of the viewcontroller (my viewcontroller is called TextViewController), something like this:
See this image: http://i48.tinypic.com/qq5yk7.jpg
But how can I make TextViewController use the UINavigationItem I added? The button I add doesn't show in the navigationbar.
Any ideas on how to do this? What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以。
您所要做的就是将 UIBarButtonItem 从对象库拖动到 Xib 的相应导航栏。
之后你就可以连接它成为你的类的 IBOutlet。
You can.
All you have to do is drag UIBarButtonItem from Object Library to corresponding NavigationBar of your Xib.
After that then you can connect it to become an IBOutlet of your class.
您可以在编码中使用一个栏按钮,例如 IBOutlet UIBarButtonItem * saveButton;
然后你必须在 xib 文件中取一个栏按钮并将该按钮与该按钮绑定,并且在编码中你可以直接编写
self.navigationItem.rightBarButtonItem = saveButton;
它几乎与您的代码相同,但唯一的变化是您不必初始化栏按钮..
快乐编码...
You can take a bar button in the coding like IBOutlet UIBarButtonItem * saveButton;
Then you have to take a bar button in the xib file and bind this button with that and in coding you can directly write
self.navigationItem.rightBarButtonItem = saveButton;
Its almost the same as your code but the only thing changes is you dont have to initialize the barbutton..
Happy coding...