The "back button" of a UINavigationController
by default shows the title of the last view in the stack. Is there a way to have custom text in the back button instead?
In view controller A, create a UIBarButtonItem with any title you want and set it to navigationItem. backBarButtonItem . This will set a back button title to "You back button title here". To make the title empty, just set the title to nil or an empty string "" .
From this link:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Custom Title" style:UIBarButtonItemStylePlain target:nil action:nil];
As Tyler said in the comments:
don't do this in the visible view controller, but in the view controller that you'd see if you hit the back button
You can set the text in the Interface Builder:
Select the navigation item of the ViewController that the back button would return to:
In the utilities panel attribute inspector, enter your label for the Back Button:
I would prefer this approach over setting the title in code as in the accepted answer.
Also note, you need to do this in the view controller one level up the stack. In other words, don't do this in the visible view controller, but in the view controller that you'd see if you hit the back button.
--Tyler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With