David Gao
David Gao

Reputation: 906

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?

Upvotes: 1

Views: 1487

Answers (1)

willcodejavaforfood
willcodejavaforfood

Reputation: 44093

There is an easy 'hack' to solve this. Set the title of the parent view to whatever you want the back button to show and then push the controller. Don't forget to change the title back when you pop the view of the second controller.

self.title = @"back";
[self.navigationController push...];

Or create a new button:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];

Upvotes: 2

Related Questions