0

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?

Andre Cytryn
  • 2,506
  • 4
  • 28
  • 43
  • 1
    You can't do that. It's not part of the appearance at all. If you have structurally common elements, create a common `UIViewController` subclass that sets up the right bar button item, then create your three others as subclasses of that. – Jason Coco Aug 28 '12 at 22:20

1 Answers1

2

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];
schubam
  • 46
  • 3