Search code examples
iphoneuinavigationcontrolleruinavigationitem

How can I change the back navigation bar button item text?


I am working on a navigation based application. Until now I am able to do this:

self.navigationItem.title=self.Category;
UIBarButtonItem *btnNewGame = [[UIBarButtonItem alloc] initWithTitle:@"New Game" style:UIBarButtonItemStyleBordered
                                                            target:self action:@selector(btnNewGameclicked:)];
self.navigationItem.rightBarButtonItem = btnNewGame;
[btnNewGame release];

and then I can call the method provided by the selector. No problems since here.

What happens now is that I have the left bar button item, the title and the right bar button item.

Problem

The title on the left bar button item is not back, but it appears to be the same as the navigation item's title. How can I change this? Any suggestions?

Thanks.


Solution

  • default behaviour of the left bar button item, is to display the title of the previous view Controller

    if you want to change the text on the left bar button item, you need to replace the left (back) button like this

    UIBarButtonItem *myBarButtonItem = [[UIBarButtonItem alloc] init];
    myBarButtonItem.title = @"Back"; // or whatever text you want
    self.navigationItem.backBarButtonItem = myBarButtonItem;
    [myBarButtonItem release];