How to change the text of UINavigationBar back button?
I want to ask a question about the iPhone application. I create the UINavigationController programmatically. And I use the UITableView开发者_如何学JAVA to do the following thing. However, I don't know how to change the text of the text in the back button (see below, in this case is 'Plays') in code level? Thank you very much.
alt text http://www.freeimagehosting.net/image.php?02730817e4.png
Link: http://www.freeimagehosting.net/image.php?02730817e4.png
To customize the back button you modify the view controller you are going back to. So you can either set the title for your "Plays" view controller:
- (void)viewDidLoad {
// ...
[self setTitle:@"Whatever"];
}
Or access the back button item:
- (void)viewDidLoad {
// ...
// target/action must be nil
self.navigationItem.backBarButtonItem =
[[[UIBarButtonItem alloc] initWithTitle:@"Whatever"
style:UIBarButtonItemStyleBordered
target:nil action:nil] autorelease];
}
You have to actually change the text of the back button before pushing the new view controller onto the stack.Otherwise the back button text will not be displayed.
put this in you viewDidLoad, and i think you will get what you need.
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"yourTitle"
style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
精彩评论