2011-08-31 46 views

回答

2

從您的描述中,聽起來您已經正確設置了UINavigationController。您所描述的「橫幅欄」正確地稱爲導航欄。

從詳細信息視圖中,可以使用:

UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithTitle:"HiMom" style:UIBarButtonItemStylePlain target:self action:@selector(onHiMom:)] autorelease]; 
self.navigationItem.rightBarButtonItem = button; 

您還可以添加自定義視圖(而不是一個按鈕),加上其他一些設置。我建議圍繞UINavigationItem,UINavigationBar和UIBarButtonItem的文檔尋找想法。

+0

輝煌。謝謝。當然,我真正想要做的是在導航欄中添加三個單獨的按鈕。似乎這樣做,我將不得不設置更復雜的東西。 –

+0

就像分段控制一樣?我最近在這裏看到類似的東西。您可以使用自定義視圖(例如,包含三個按鈕)創建BarButtonItem,或者使用自定義視圖(通過導航項目的titleView屬性)替換標題視圖,並將按鈕放在那裏。 – AndrewS

5

正如Andrew所說,您可以將自定義視圖添加到導航欄中。例如,如果你正在尋找多個按鈕添加到導航欄的右側,你可以做這樣的事情:

// right side of nav bar 
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 106, 44)]; 
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3]; 

UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc] 
           initWithBarButtonSystemItem:UIBarButtonSystemItemTrash 
           target:self 
           action:@selector(deleteAction:)]; 
deleteButton.style = UIBarButtonItemStyleBordered; 
[buttons addObject:deleteButton]; 
[deleteButton release]; 

UIBarButtonItem *spacer = [[UIBarButtonItem alloc] 
          initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace 
          target:nil 
          action:nil]; 
[buttons addObject:spacer]; 
[spacer release]; 

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] 
           initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
           target:self 
           action:@selector(cancelAction:)]; 
cancelButton.style = UIBarButtonItemStylePlain; 
[buttons addObject:cancelButton]; 
[cancelButton release]; 

[toolbar setItems:buttons animated:NO]; 
toolbar.barStyle = -1; 
[buttons release]; 

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

確認是否需要調整寬度(以上106)以上或更寬按鈕,然後爲選擇器提供方法(deleteAction:和cancelAction:上方)。

+0

完美。我幾乎在我身邊:D謝謝。 –

+0

戴夫:如果答案幫助你,你可以點擊上/下數字下方的小檢查標記爲接受的答案?謝謝。 –

相關問題