views:

661

answers:

2

The Situation:
I have a UIViewController that is governed by a navigation controller. I am able to set the title of the navigation bar covering the UIViewController by simply calling self.title = @"title". But, I want to be able to set the back button text of the navigation bar, too (for different languages n' such..)

The Problem:
I don't know how to set the back button's text.

The Question:
How do I set the back button of the UINavigation bar (programmatically not in IB)?

Thanks dudes. And good luck to the nominees of the 2010 moderator election.

+2  A: 

Check out this answer to the same question.

Matthew McGoogan
Beat me to it! This is the correct answer. Don't modify the title before pushing a new controller.What's confusing is that the back button is part of the parent controller, not the one that's currently displayed.
dk
How do you figure that it's "the correct answer"? You mean there is only one answer? Weird.
Matt Long
+2  A: 

You either have to replace the back button with your own by changing the left bar button item, in which case it won't be the spiffy left pointing button. Or, you have to set the title of the calling view controller. You can do this right before you push the new view controller. Like this (for example):

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self setTitle:@"Back Button Text"];
    SecondViewController *controller = [[SecondViewController alloc] init];
    [[self navigationController] pushViewController:controller animated:YES];
    [controller release];
}

Then reset it in -viewWillAppear of your calling view controller so that when it re-appears after the second controller is popped, it will have the original text.

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setTitle:@"View Header Text"];
}

Best regards,

Matt Long