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?

4

1 回答 1

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];
于 2012-08-28T22:26:28.703 回答