views:

37

answers:

1

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];
}
+2  A: 

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.

GregInYEG
it doesn't change anything....
EquinoX
I upvoted his answer. The only time I've ever had an issue with navigation bar buttons is when a button is initiated with a custom image that is nil. The only thing I can suggest is to set a breakpoint and verify that the button is not nil.
JustinXXVII
I edited my answer to include something else you can try.
GregInYEG