Search code examples
iphoneobjective-cback-buttonuinavigationitem

How to change the text on a Back Button?


I've created a Navigation Controller, with a bar button item. This button leads me to another view, and perfectly creates a back button. I just want to change the text of this button, so I typed it in Navigation Item > Attributes Inspector > Back Button, but it doesn't work and I've the following warning :

Title set but using a system Identifier (These attributes are mutually exclusive; the Title will be ignored)

What should I do ?


Solution

  • Changing the Back button is easy, here are ways to change to either text or an image, you will want to place these in your viewDidLoad method.

    UIImage:

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
    [backButton setImage:[UIImage imageNamed:@"back_home.png"]];
    self.navigationItem.backBarButtonItem = backButton;
    [backButton release];
    

    NSString:

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
    [backButton setTitle:@"Go Back!"];
    self.navigationItem.backBarButtonItem = backButton;
    [backButton release];