我想向UIBarButtonItem
添加许多UINavigationbar
,而不仅仅是左右按钮:
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;
我在SIGBRT
self.navigationController.navigationBar.items = items;
如何将多个UIBarButtonItem
添加到UINavigationBar
?
答案 0 :(得分:17)
您需要将UIBarButtonItem
个实例添加到UINavigationItem
,而不是UINavigationBar
。所以你可以这样做:
NSArray *buttonArray = [NSArray arrayWithObjects:logoButton, logoButton2, logoButton3, nil];
self.navigationItem.leftBarButtonItems = buttonArray;
如果您想要右侧的按钮,请使用rightBarButtonItems
。
答案 1 :(得分:4)
你应该使用
self.navigationItem.leftBarButtonItems = items;
答案 2 :(得分:-1)
在导航栏中使用addSubView。