How to change text on a back button
By default the back button uses as a text on it a title of a viewcontroller. Can I change text on the back button without changing a title of a view controller? I need this because I have a view controller which title is too long to display and in this case I would like to display just "Back" as a caption for back button.
I tried the following which didn't work:
self.navigationItem.leftBarButtonItem.title = @"Back";
Thanks.
Solution 1:
Try
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
I found that by looking at the backBarButtonItem docs in Apple's docs for UINavigationItem.
Solution 2:
Marc W's approach worked great once I figured out which controller to apply it to: the one being re-titled, not the one on top. So if this is the navigation stack:
(bottom) ControllerA -> ControllerB (top)
...and you want to give a shorter title for ControllerA in the back-button displayed when ControllerB is on top, you apply the property change to ControllerA.
So it's more in the context of self.title
, not like the other left/right-bar-button setters.