2010-03-12 62 views
0

我正在開發與UITabBarController作爲主視圖的iPhone應用程序。每個選項卡中的每個ViewController都是UINavigationController,它必須在leftBarButtonItem中具有相同的按鈕。我可以從UINavigationController繼承一些類並覆蓋它 - (id)initWithRootViewController:(UIViewController *)rootViewController方法來實現這一點?從UINavigationController繼承

我做了這樣的事情。但是這個代碼不起作用;

@implementation MainNavagaionController 
-(id) initWithRootViewController:(UIViewController *)rootViewController { 
    if (self = [super initWithRootViewController:rootViewController]) { 
     // Set user name title 
     UIBarButtonItem * userNameButton = [[UIBarButtonItem alloc] initWithTitle:@"Title" 
        style:UIBarButtonItemStylePlain 
        target:self 
        action:nil]; 
     self.navigationItem.leftBarButtonItem = userNameButton; 
     [userNameButton release]; 
    } 
return self; 
} 
@end 

回答

0

導航欄中顯示的是每個導航控制器中當前視圖控制器的navigationItem。設置此左側欄按鈕時,您的級別太高。