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.
I've found that it is best to change the title of the current view controller in the navigation stack to the desired text of the back button before pushing to the next view controller.
For instance
Then in the viewDidAppear set the title back to the desired title for the original VC. Voila!
In ChildVC this worked for me...
Works in Swift too!
None of the solutions explained here worked for me. So what I did was remove the title from the scene where I came from in the following way:
self.title = @"";
So when new scene is presented the back text does not appear.
I absoluty agree that this is not a clear solution at all, but worked and none of the explained worked for me.
PROBLEM: "Back" text in the navigation bar can not be replaced.
REASON: "Back" label is set in the navigation bar after pushing a view because the .title attribute in the parent view controller was set to nil (or not initialised).
ONE SOLUTION: If you set the self.title="Whatever..." you will see that instead of "Back" will appear "Whatever..." after pushing new view controller.
This should be placed in the method that calls the ViewController titled "NewTitle". Right before the push or popViewController statement.
in Xcode 4.5 using storyboard, by far the easiest solution i've found when the value of the Back button doesn't have to change dynamically is to use the "Back Button" field associated with the Navigation Item of the View Controller to which you want the "Back" button to say something else.
e.g. in the screenshot below, i want the Back button for the view controller(s) that i push to have "Back" as the title of the Back button.
of course, this won't work if you need the back button to say something slightly different each time … there are all of the other solutions here for that.