0

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.

marzapower
  • 5,531
  • 7
  • 38
  • 76
maddy
  • 4,001
  • 8
  • 42
  • 65
  • Possible duplicate of http://stackoverflow.com/questions/1441699/uinavigationcontroller-back-button-custom-text – Joel May 06 '12 at 19:43

4 Answers4

3

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];
Matt
  • 4,253
  • 1
  • 27
  • 29
  • 1
    thank you very much .i have to change in your code as:self.navigationItem.backBarButtonItem to self.navigationItem.LEFTBarButtonItem. – maddy May 27 '11 at 09:48
0

Try this way in the viewDidLoad method:

self.navigationController.navigationBar.topItem.title = @"YourBack";

This worked for me.

Pedro Trujillo
  • 1,559
  • 18
  • 19
0

As per your question what i understand , your problem is that the title of leftbarbuttonitem is not Back, this is because you gave the previous screen some title.That's why leftbarbutton item shows the title of navigation-item and not as Back.To remove that you must have erase the title of previous view or do it pro-grammatically as given by Matt.

Aman Aggarwal
  • 3,754
  • 1
  • 19
  • 26
0

And why not

self.navigationItem.leftBarButtonItem.title = @"MyTitle";

?

Luis Andrés García
  • 5,852
  • 10
  • 43
  • 57