Customize back bar button item title

When developing navigation controller-based apps, it’s pretty common to want to customize the title of the back button that is displayed on the navigation bar. Usually the button title is set to the parent view controller’s title, but you can customize that.

All you need to do is add some code to the viewDidLoad method in the parent view controller:

– (void) viewDidLoad
{
    [super viewDidLoad];

    self.title = @”Title goes here”;
 
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@”Back”
                            style:UIBarButtonItemStyleBordered
                            target:nil
                            action:nil];

    self.navigationItem.backBarButtonItem = backButton;   // Affect child view controller’s back button.
    [backButton release];
 }

Blogged with the Flock Browser
Advertisements