修改返回按鈕 標題 (UINavigationBar)

UINavigationController Class Reference,在「Updating the Navigation Bar」小節,有這麼一段話: ide

The bar button item on the left side of the navigation bar allows for navigation back to the previous view controller on the navigation stack. The navigation controller updates the left side of the navigation bar as follows: spa

  • If the new top-level view controller has a custom left bar button item, that item is displayed. To specify a custom left bar button item, set the leftBarButtonItem property of the view controller’s navigation item.
  • If the top-level view controller does not have a custom left bar button item, but the navigation item of the previous view controller has a valid item in itsbackBarButtonItem property, the navigation bar displays that item.
  • If a custom bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the title property of the previous view controller—that is, the view controller one level down on the stack. (If there is only one view controller on the navigation stack, no back button is displayed.)

我大體解釋一下,使用pushViewController切換到下一個視圖時,navigation controller按照如下3條順序更改導航欄的左側按鈕。 .net

一、若是B視圖有一個自定義的左側按鈕(leftBarButtonItem),則會顯示這個自定義按鈕; code

二、若是B沒有自定義按鈕,可是A視圖的backBarButtonItem屬性有自定義項,則顯示這個自定義項; ci

三、若是前2條都沒有,則默認顯示一個後退按鈕,後退按鈕的標題是A視圖的標題。 get

按照這個解釋,我把UIBarButtonItem *backItem……這段代碼放在A視圖的pushViewController語句以前。 it

OK問題解決了,B視圖的後退按鈕的標題變成back了。 io

 

UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:nilaction:nil]
[self.navigationItem setBackBarButtonItem:backItem];
  [backItem release]
[self.navigationController pushViewController:self.bView animated:YES];

轉載自:http://zgia.net/?p=306 sed

相關文章
相關標籤/搜索