views:

57

answers:

2

Hi,

I'm trying to change Back Button tittle in a navigation controller in the following way:

In the parent controller I put this in vieDidLoad:

self.title = @"Calendars";
self.navigationItem.backBarButtonItem.title = @"Previous";

But this controller is in the stack since I initialized the app:

-(void)applicationDidFinishLaunching:(UIApplication *)application{

navController.viewControllers= [NSArray arrayWithObjects:aController,aBcontroller,nil];
[window addSubview:navController.view];

}

So, the viewDidLoad in aController is not called until I select the back buttom the first time in the bController...

Does anyone knows how to call viewDidLoad just when I push it into the stack? Or do you know another way to change the BackButtom title?

Thanks in advanced for your help.

A: 

You should put your code to set up the title and navigationItem in init, you don't need to wait until the view is loaded.

Brian
This will work for the title, but not for the Back button. It will set the backButtonItem's title to be aController's title rather than "Previous".
Drew C
For some reason it only works if you create the button yourself: `self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Previous" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease];`
Brian
A: 

You can set the title of the back button for any ViewController you're in with the following line of code:

self.navigationController.navigationBar.backItem.title = @"Previous";
Drew C
Thanks! This worked for me
Rafael
Just a litle note: In order to make it work as I expected, I put the code above in - (void)viewDidAppear:(BOOL)animated
Rafael
Note that you may need to set the title back to the original value in viewWillDisappear. Also, I can see the back button quickly change title after the animated slide, so this technique isn't flawless.
Jason Moore