aherlambang
aherlambang

Reputation: 14418

right bar button not loading in navigation bar

I have the following code inside my @interface FriendsNavController : UINavigationController class implementation. The code is executed. I just don't know why it's not showing the button...

- (void)viewDidLoad {
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"Add Event" style:UIBarButtonItemStylePlain target:self action:@selector(refreshPropertyList)];
    self.navigationItem.rightBarButtonItem = button;
    [button release];
    [super viewDidLoad];
}

Upvotes: 0

Views: 974

Answers (1)

Greg
Greg

Reputation: 33650

EDIT: I think I misread your question. I set the navigationItem.rightBarButtonItem in the viewDidLoad of the controller that I push onto the navigation controller's stack, not in the viewDidLoad of the navigation controller. I think this is what you'll need to do as well.


Perhaps the call to [super viewDidLoad] is setting the navigation item's buttons back to the default (i.e., none). In my navigation-based app, I make the [super viewDidLoad] call before my code, like this:

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"Add Event" style:UIBarButtonItemStylePlain target:self action:@selector(refreshPropertyList)];
    self.navigationItem.rightBarButtonItem = button;
    [button release];
}

and the right button is appearing correctly.

Upvotes: 2

Related Questions