views:

24

answers:

1

Hi. I'm developing iphone app with UITabBarController as main view. Every ViewController in each tab is UINavigationController which must have a same button in leftBarButtonItem. Can I inherit some class from UINavigationController and override it's -(id) initWithRootViewController:(UIViewController *)rootViewController method to realize this ?

I made something like this. But this code doesn't work;

@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
A: 

What is shown in the navigation bar is the navigationItem of the current viewcontroller in each navigation controller. You are one level too high when you are setting this left bar button.

Johan Kool