UINavigationController "back button" custom text?

Solution 1:

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

Solution 2:

You can set the text in the Interface Builder:

Select the navigation item of the ViewController that the back button would return to:

enter image description here

In the utilities panel attribute inspector, enter your label for the Back Button:

enter image description here

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

Solution 3:

I use this:

// In the current view controller, not the one that is one level up in the stack
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.backItem.title = @"Custom text";
}

Solution 4:

I found a handy solution to this by simply setting the title of the controller before pushing another controller onto the stack, like this:

self.navigationItem.title = @"Replacement Title";
[self.navigationController pushViewController:newCtrl animated:YES];

Then, make sure to set the original title in viewWillAppear, like this:

-(void)viewWillAppear:(BOOL)animated
{
  ...
  self.navigationItem.title = @"Original Title";
  ...
}

This works because the default behavior of UINavigationController when constructing the back button during a push operation is to use the title from the previous controller.

Solution 5:

The title of the back button defaults to the previous view's title so a quick trick I use is to place the following code on the previous view's .m file.

-(void)viewWillAppear:(BOOL)animated {

    // Set title
    self.navigationItem.title=@"Original Title";
}

-(void)viewWillDisappear:(BOOL)animated {

    // Set title
    self.navigationItem.title=@"Back";
}