How to change text on a back button

Ilya Suzdalnitski picture Ilya Suzdalnitski · May 7, 2009 · Viewed 65.1k times · Source

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.

Answer

Marc W picture Marc W · May 7, 2009

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.