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