Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to change the title of the backbaritem in uinavigationcontroller

in my code, i have this line
[self.navigationItem.backBarButtonItem setTitle:@"back"];
but this doesn't change the title of the back button in uinavigationcontroller when the new controller is pushed.
So how to change the title of the back button?

iOS 4

Posted on Jul 16, 2010 1:26 PM

Reply
Question marked as Best reply

Posted on Jul 16, 2010 7:05 PM

Hi David -

The title of the default back button can't be changed. I.e. it will always be the title of the back navigation item. So you need to create a new back button. E.g.:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
AnotherViewController *anotherViewController =
[[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]
initWithTitle:@"To Previous" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = barButtonItem;
[barButtonItem release];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
}

For the root view controller's back button (i.e. the back button displayed by the view just above the root) you can change the title in IB by selecting the root view controller's nav item (e.g. in MainWindow.xib), and setting the +Back Button+ field in the Attributes Inspector. But for higher view controllers, the above example code is much easier.

- Ray
1 reply
Question marked as Best reply

Jul 16, 2010 7:05 PM in response to Daviiidddd

Hi David -

The title of the default back button can't be changed. I.e. it will always be the title of the back navigation item. So you need to create a new back button. E.g.:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
AnotherViewController *anotherViewController =
[[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]
initWithTitle:@"To Previous" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = barButtonItem;
[barButtonItem release];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
}

For the root view controller's back button (i.e. the back button displayed by the view just above the root) you can change the title in IB by selecting the root view controller's nav item (e.g. in MainWindow.xib), and setting the +Back Button+ field in the Attributes Inspector. But for higher view controllers, the above example code is much easier.

- Ray

How to change the title of the backbaritem in uinavigationcontroller

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.