Questions
Questions

Reputation: 20875

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 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

Upvotes: 0

Views: 3240

Answers (3)

Ravi_Parmar
Ravi_Parmar

Reputation: 12329

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];

Upvotes: 1

Mike Weller
Mike Weller

Reputation: 45598

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];
}

Upvotes: 3

Mahadevan S
Mahadevan S

Reputation: 11

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.

Upvotes: 1

Related Questions