How do I change the title of the "back" button on a Navigation Bar

Dale picture Dale · Sep 19, 2009 · Viewed 203.2k times · Source

Currently the left bar button default value is the title of the view that loaded the current one, in other words the view to be shown when the button is pressed (back button).

I want to change the text shown on the button to something else.

I tried putting the following line of code in the view controller's viewDidLoad method but it doesn't seem to work.

self.navigationItem.leftBarButtonItem.title = @"Log Out";

What should I do?

Thanks.

Answer

Jordan picture Jordan · Sep 19, 2009

This should be placed in the method that calls the ViewController titled "NewTitle". Right before the push or popViewController statement.

UIBarButtonItem *newBackButton = 
        [[UIBarButtonItem alloc] initWithTitle:@"NewTitle" 
                                         style:UIBarButtonItemStyleBordered 
                                        target:nil 
                                        action:nil];
[[self navigationItem] setBackBarButtonItem:newBackButton];
[newBackButton release];