iOS - UINavigationController添加多个正确的项目?

ary*_*axt 33 iphone objective-c uinavigationcontroller ios

我有一个UINavigationController.我正在尝试在navigationBar的右侧添加多个按钮.我怎样才能做到这一点?需要什么样的按钮?UIBarButton还是UINavigationItem

jrt*_*ton 80

从iOS5开始,您可以将一个条形按钮项目数组分配给导航项目rightBarButtonItems(注意复数)属性.

  • 这应该是真正接受的答案:) (2认同)

wzb*_*zon 28

我在Xcode 4.5,iOS 6中使用了JRTurtons的答案并且像这样实现它并且它的工作原理:

// Two buttons at the right side of nav bar
UIBarButtonItem *addAttachButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAttachmentClicked:)];
UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:LS(@"Send") style:UIBarButtonItemStyleBordered target:self action:@selector(sendClicked:)];
self.navigationItem.rightBarButtonItems = @[addAttachButton,sendButton];
Run Code Online (Sandbox Code Playgroud)

但是,我应该提一下,UIBarButtonSystemItemPageCurl并不像那样工作.


Dea*_*ids 15

我确信我在开发人员参考中读到导航栏中的其他按钮不受欢迎.我现在找不到那段话.我自己没有这样做,但发现这个链接似乎正好勾勒出你需要做的事情: (http://www.mattdipasquale.com/blog/2010/11/02/how-to-add-multiple-uibarbuttonitems -to-UINavigationBar的/)

您是否考虑过使用导航控制器的工具栏属性?

  • 如果你说正确的另外正确的按钮按钮是正确的,那么jrturton指出的iOS5中的新属性证明Apple愿意改变主意.非常鼓舞人心 (这意味着上述黑客可能会在提交时被接受.) (3认同)
  • 链接不再有效,解释不再适用.你能更新一下吗? (2认同)