標籤:style http color 使用 strong os
兩個辦法:
1, 手動為每一個UIViewController添加navigationItem的leftButton的設定代碼
2,為UINavigationController實現delegate,在pop和push的時候改變當前和上一頁的navigationItem.title
以下是封裝的一些基礎方法,供參考:
+ (void) navigationItem:(UINavigationItem*)navigationItem
setTitle:(NSString*)title;
+ (void) navigationItem:(UINavigationItem*)navigationItem
setBackButton:(NSString*)title
addTarget:(id)target
action:(SEL)action;
+ (void) navigationItem:(UINavigationItem*)navigationItem
setImage:(NSString*)imageString;
無奈之下,只好研讀UINavigationController Class Reference去,在“Updating the Navigation Bar”小節,有這麼一段話:
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:
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 its backBarButtonItemproperty, 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條順序更改導覽列的左側按鈕。
1、如果B視圖有一個自訂的左側按鈕(leftBarButtonItem),則會顯示這個自訂按鈕;
2、如果B沒有自訂按鈕,但是A視圖的backBarButtonItem屬性有自訂項,則顯示這個自訂項;
3、如果前2條都沒有,則預設顯示一個後退按鈕,後退按鈕的標題是A視圖的標題。
按照這個解釋,我把UIBarButtonItem *backItem……這段代碼放在A視圖的pushViewController語句之前。
OK問題解決了,B視圖的後退按鈕的標題變成back了。
eg:
UIBarButtonItem*backItem=[[UIBarButtonItemalloc]init];
[email protected]"戻る";
self.navigationItem.backBarButtonItem=backItem;
[backItem release]
==============
新方案:
self.navigationController.navigationBar.topItem.title=self.message;
self.navigationController.navigationBar.tintColor=[UIColorblackColor];
UIBarButtonItem*backButton = [[UIBarButtonItemalloc] initWithTitle:@" fan hui "style:UIBarButtonItemStyleBorderedtarget:selfaction:@selector(PopViewController)];
self.navigationItem.leftBarButtonItem= backButton;
以上轉自:http://hi.baidu.com/myyuchong/item/1e6db306c5d34de1359902a1
PS:在第三種情況的時候,自動建立的返回按鈕只取了A視圖的title值,其他屬性並沒有複製,看來要改變顏色等別的屬性還得自訂一個返回按鈕啊