如何在UINavigationBar上设置后退按钮的文本? [英] How to set the text of a back button on a UINavigationBar?

查看:159
本文介绍了如何在UINavigationBar上设置后退按钮的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何更改后退按钮的标题?导航栏上的按钮

情况:

我有一个由导航控制器管理的UIViewController。我可以通过简单地调用 self.title = @title来设置覆盖UIViewController的导航栏的标题。但是,我希望能够设置导航栏的后退按钮文本(对于不同的语言,这样......)

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.

问题:

如何设置UINavigation栏的后退按钮(以编程方式不在IB中)?

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

推荐答案

setTitle方式 - 虽然看似有效,但是不正确。如果您仔细关注,您会注意到导航项目更改为新标题,同时通过pushViewController将新视图设置为视图。您必须在viewWillAppear中恢复标题的事实是kludgy,这进一步暗示了它的黑客性质。

The setTitle way - though may seem to work, is incorrect. If you pay attention closely, you will notice that the navigation item changes to the new title while the new view is animated into view via pushViewController. The fact that you have to restore your title in viewWillAppear is kludgy, which further suggests its hack nature.

正确的方法是在pushViewController之前执行以下操作:

The correct way is to do the following before your pushViewController:


UIBarButtonItem *backButton = [[UIBarButtonItem alloc] 
                                initWithTitle: @"Back Button Text" 
                                style: UIBarButtonItemStyleBordered
                                target: nil action: nil];

[self.navigationItem setBackBarButtonItem: backButton];
[backButton release];

这篇关于如何在UINavigationBar上设置后退按钮的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆