如何更改后退导航栏按钮项目文本?

发布于 2024-11-09 21:51:52 字数 571 浏览 0 评论 0原文

我正在开发一个基于导航的应用程序。到目前为止我可以这样做:

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

然后我可以调用选择器提供的方法。从这里开始就没有问题了。

现在发生的是我有左栏按钮项目、标题和右栏按钮项目。

问题

左侧栏按钮项的标题不是 back,但它似乎与导航项的标题相同。我怎样才能改变这个?有什么建议吗?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

云淡月浅 2024-11-16 21:51:52

左栏按钮项目的默认行为是显示上一个视图控制器的标题

如果要更改左栏按钮项目上的文本,则需要像这样替换左(后退)按钮

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

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];
幽蝶幻影 2024-11-16 21:51:52

根据我理解的您的问题,您的问题是 leftbarbuttonitem 的标题不是后退,这是因为您给了前一个屏幕一些标题。这就是为什么 leftbarbutton 项目显示导航项的标题而不是后退。要删除它您必须删除先前视图的标题或按照马特给出的编程方式执行此操作。

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.

蓝戈者 2024-11-16 21:51:52

为什么不呢

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

And why not

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

?

粉红×色少女 2024-11-16 21:51:52

viewDidLoad 方法中尝试这种方式:

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

这对我有用。

Try this way in the viewDidLoad method:

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

This worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文