如何设置 UINavigationBar 上后退按钮的文本?
可能的重复:
如何更改导航栏上“后退”按钮的标题
情况:
我有一个由导航控制器控制的 UIViewController。我可以通过简单地调用 self.title = @"title" 来设置覆盖 UIViewController 的导航栏的标题。但是,我也希望能够设置导航栏的后退按钮文本(对于不同的语言等......)
问题:
我不知道如何设置后退按钮的文本。
问题:
如何设置 UINavigation 栏的后退按钮(不在 IB 中以编程方式设置)?
Possible Duplicate:
How do I change the title of the “back” button on a Navigation Bar
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.
The Question:
How do I set the back button of the UINavigation bar (programmatically not in IB)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
setTitle 方法虽然看起来可行,但却是不正确的。如果您仔细观察,您会注意到导航项更改为新标题,同时新视图通过 PushViewController 动画化到视图中。事实上,你必须在 viewWillAppear 中恢复你的标题是很糟糕的,这进一步表明了它的黑客性质。
正确的方法是在pushViewController之前执行以下操作:
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.
The correct way is to do the following before your pushViewController:
根据苹果文档,将视图控制器的标题设置为背面应显示的内容的最佳和最简单的方法是这样的 -
示例:
如果
viewController1
位于viewController2(并且
viewController2
上的后退按钮
将转到viewController1
)viewController2 上的
将显示“很棒的东西”后退按钮
The best and easiest way according to apple documentation to set the view controller's title to what the back should say is this -
Example:
If
viewController1
is underviewController2
(and theback button
onviewController2
is going toviewController1
)the
back button
onviewController2
will show "something awesome"