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.
For those using storyboards just select the parent (not the one that is holding target view) view controller frame (be sure you click right on the Navigation bar, then open attributes inspector, where you'll find three form inputs. The third one "back button" is that we are looking for.
This works for me as a "simplified" version of previous posted answers.
Remember to put the code inside the parent view controller (e.g. the view that has your table view or UITableViewController), not the child or detail view (e.g. UIViewController).
You can easily localize the back button string like this:
I know, the question is very old, but I found a nice solution.
Works from childView! Tested with iOS 7.
Swift version:
In your child ViewController:
I've found, that the easiest way to change the name of the back button is to set the view controllers title to the title of the back button, and then replacing the titleView in the view controllers navigation item to a custom label with it's real name.
Like this:
CustomViewController.m
This will make your title in UINavigationBar look as if it was native. Giving the view controller the ability to have seperated title and back button title.
In the case of view controller A and B, A is responsible for telling how it's back button should look, while B is displayed.
EDIT: This also maintains the back button native look (The left arrowed bar button item).
In Swift/iOS8, the following worked for me:
Ported from Felipe's answer.