views:

46

answers:

2

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?

A: 

Two ways to solve these kind of annoying problems:

1) assign your own UIBarButtonItem to navigationItem.backBarButtonItem, e.g. in -(void)viewDidLoad

2) check the timing, assign the text or button not too early, i.e. after the iphone did it's thing

mvds
This is not very helpful
St3fan
without more context we cannot provide more help I think, so I suggested just 2 strategies. What would you suggest then?
mvds
there are just too many possible reasons why the line as suggested wouldn't work
mvds
A: 

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];
willcodejavaforfood
this hack shows that the underlying problem is that the back button title is set at a later stage. You'd better find a more suitable place to set the back button title, or assign your own back button at some point.
mvds