Reputation: 2705
Sup guys,
I have a tabBarController with a navigationController on each tab.
I wanted to set de default right bar button of navigation bar so I wouldn't have to write the same code on 3 different view controllers.
I tried [[UINavigationBar appearance] setRightBarButtonItem:myButton];
but had no success, is says:
-[_UIAppearance setRightBarButtonItem:]: unrecognized selector sent to instance
Then I tried to create my own UINavigationController subclass so I could set the button like:
self.navigationItem.rightBarButtonItem = myButton
but again no success, nothing seems to happen probably because I dont have a navigationItem at this time.
Anyone have another solution?
Upvotes: 0
Views: 849
Reputation: 46
If you inherit from the UIViewController
you can set the right button like this
UIBarButtonItem * rightButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"foobar.png"] style:UIBarButtonItemStylePlain target:self action:@selector(myAction)];
self.navigationItem.rightBarButtonItem = rightButton;
[rightButton release];
Upvotes: 2