如何向NavigationBar添加多个按钮?

Mat*_*att 7 iphone cocoa-touch

好的,所以我成功添加了一个rightBarButtonItem来调用自定义选择器(从UIViewController调用),如下所示:

 UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];

 [infoButton addTarget:self action:@selector(showInfoView:) forControlEvents:UIControlEventTouchUpInside];

 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
Run Code Online (Sandbox Code Playgroud)

是否可以使"右栏按钮项"实际上是几个不同的按钮(从而从导航栏中删除标题文本)?

我正在寻找获得更多屏幕空间的方法,这似乎是一个合乎逻辑的选择......虽然任何其他建议都会受到赞赏(也许我应该减少我在底部使用的标签栏的大小......)

iPh*_*lly 21

UIBarButtonItem *addAcc = [[UIBarButtonItem alloc] 
                               initWithTitle:@"Add"                                            
                               style:UIBarButtonItemStylePlain 
                               target:self 
                               action:@selector(addNewAcc)];

UIBarButtonItem *delAcc = [[UIBarButtonItem alloc] 
          initWithTitle:@"Del"                                            
          style:UIBarButtonItemStylePlain 
          target:self 
          action:@selector(DeleteButtonAction)];

NSArray *arrBtns = [[NSArray alloc]initWithObjects:addAcc,delAcc, nil];
self.navigationItem.rightBarButtonItems = arrBtns;
Run Code Online (Sandbox Code Playgroud)

  • @JayprakashDubey,我假设你不小心把'.rightBarButtonItems'的's'从最后一行留下了,产生了你的错误.希望你能让它继续工作! (3认同)

Ed *_*rty 0

好吧,您可以使用UISegmentedControl带有栏样式的 a 。或者您可以添加通用UIView并添加您想要的任何按钮。