Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
You need to set the title of the navigationItem before you push the new viewController onto the stack. So, something like:
Code:
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

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
You need to set the title of the navigationItem before you push the new viewController onto the stack. So, something like:
Code:
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

macrumors 6502
Oct 31, 2007
395
1
San José
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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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

macrumors 6502
Oct 31, 2007
395
1
San José
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.