Search code examples
iosiphonecocoa-touchuinavigationitem

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

  • 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.