简体   繁体   中英

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.

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

Try this way in the viewDidLoad method:

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

This worked for me.

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.

And why not

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

?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM