本文介绍了如何添加多个UIBarButtonItem到UINavigationBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想向 UINavigationbar
添加许多 UIBarButtonItem
,而不仅仅是左右按钮:
I want to add many UIBarButtonItem
's to a UINavigationbar
, not just right and left buttons:
logoButton = [[UIBarButtonItem alloc] initWithTitle:@"A Button" style:UIBarButtonItemStyleBordered target:self action:@selector(logoButtonAClicked:)];
logoButton2 = [[UIBarButtonItem alloc] initWithTitle:@"B Button" style:UIBarButtonItemStyleBordered target:self action:@selector(logoButtonBClicked:)];
logoButto3 = [[UIBarButtonItem alloc] initWithTitle:@"C Button" style:UIBarButtonItemStyleBordered target:self action:@selector(logoButtonCClicked:)];
self.navigationController.navigationBarHidden = NO;
self.title = @"Title";
NSArray* items = [[NSArray alloc] initWithObjects:logoButtonA, logoButtonB, logoButtonC, nil];
self.navigationController.navigationBar.items = items;
我在<$ c上获得 SIGBRT
$ c> self.navigationController.navigationBar.items = items;
I get a SIGBRT
on self.navigationController.navigationBar.items = items;
如何添加多个 UIBarButtonItem
s到 UINavigationBar
?
推荐答案
将 UIBarButtonItem
实例添加到 UINavigationItem
,而不是 UINavigationBar
。所以你可以这样做:
You need to add UIBarButtonItem
instance to a UINavigationItem
, not to a UINavigationBar
. So you can do this as:
NSArray *buttonArray = [NSArray arrayWithObjects:logoButton, logoButton2, logoButton3, nil];
self.navigationItem.leftBarButtonItems = buttonArray;
如果您想要右侧的按钮,请使用 rightBarButtonItems
。
If you want your buttons on the right, use rightBarButtonItems
.
这篇关于如何添加多个UIBarButtonItem到UINavigationBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!