2010-03-09 34 views
7

好了,我已經成功地將一個rightBarButtonItem調用自定義選擇器(從一個UIViewController調用),具體如下:如何將多個按鈕添加到NavigationBar?

UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 

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

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton]; 

是否有可能作出「正確的欄按鈕項目」實際上是幾個不同按鈕(從而從導航欄中刪除標題文本)?

我在尋找方式來獲得更多的屏幕房地產,這似乎是一個合乎邏輯的選擇......雖然任何其他建議,將不勝感激(也許我應該減少標籤欄的大小,我在底部使用...)

回答

0

嗯,你可以使用一個UISegmentedControl與酒吧的風格。或者你可以添加一個通用的UIView並添加你想要的任何按鈕。

+1

@Matt是正確的UISegmented控制不是爲此目的,你應該從Apple First閱讀UIDesign參考指南。謝謝 – 2012-06-07 21:17:48

+0

公平地說,當這個答案發布時,他們的設計參考是不同的。 – 2014-10-06 14:26:06

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; 
+1

這產生一個警告...不兼容的指針轉換,從一個NSArray分配的UIBarButtonItem * _strong .. – 2013-06-26 15:15:22

+3

@JayprakashDubey,我假設你不小心留下的「s」關上產生的錯誤的最後一行「.rightBarButtonItems'的。無論如何,希望你有它的工作! – 2014-01-14 14:56:41