PDA

View Full Version : Back button title




sujithkrishnan
Mar 2, 2009, 11:04 PM
Hi all,
I want to know how to set the back button title of navigation controller.
I tried doing the following but it didn't work.
self.navigationItem.backBarButtonItem.title = @"Back";



dejo
Mar 3, 2009, 12:04 AM
You need to set the title of the navigationItem before you push the new viewController onto the stack. So, something like:
self.navigationItem.title = @"Back";
[appDelegate.navController pushViewController:nextController animated:YES];

Then don't forget to restore the title to its original value when you pop back.

sujithkrishnan
Mar 4, 2009, 12:56 AM
You need to set the title of the navigationItem before you push the new viewController onto the stack. So, something like:
self.navigationItem.title = @"Back";
[appDelegate.navController pushViewController:nextController animated:YES];

Then don't forget to restore the title to its original value when you pop back.

Thanks for the reply.It worked.

North Bronson
Mar 4, 2009, 01:51 PM
If you have a specific view controller in your navigation controller that you want to display a back button, I would try this before you push that view:

[[self navigationItem] setTitle: @"myTitle"];

UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];

[[self navigationItem] setBackBarButtonItem: newBackButton];

[newBackButton release];

Place that in the loadview or init method of your new view controller.

dejo
Mar 4, 2009, 02:13 PM
If you have a specific view controller in your navigation controller that you want to display a back button, I would try this before you push that view:

[[self navigationItem] setTitle: @"myTitle"];

UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];

[[self navigationItem] setBackBarButtonItem: newBackButton];

[newBackButton release];

Place that in the loadview or init method of your new view controller.
Does this technique allow the back button to maintain it's "arrowhead" style?

North Bronson
Mar 4, 2009, 02:23 PM
Does this technique allow the back button to maintain it's "arrowhead" style?

Yes. setBackBarButtonItem takes care of the arrowhead style.

setBackBarButtonItem also takes care of the target and action, which is why you can just init a button with no (nil) target or action. The method will add those for you.