iPhone:NavigationController 导航栏后退按钮文本
当我将新的 ViewController 推到导航控制器堆栈上时,“后退”按钮是前一个控制器的标题。
如何将后退按钮中的文本更改为“后退”而不是默认的最后一个控制器名称?
When I push a new ViewController onto a navigation controller stack the "back" button is the Title of the previous controller.
How can I change the text in the back button to "Back" instead of the default name-of-last-controller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是使用除前一页标题之外的其他内容制作后退按钮的正确方法
据我所知:
将使前一页上导航栏的标题这不是您想要的。
This is the proper way to make a back button with something other than the previous' pages title
Its to my understanding that:
will make the Title of the navigation bar on the previous page this which is not what you want.
我知道,这个问题很老了,但我找到了一个很好的解决方案。
从 childView 开始工作!使用 iOS 7 进行测试。
I know, the question is very old, but I found a nice solution.
Works from childView! Tested with iOS 7.
您需要在导航控制器上创建一个自定义按钮。将以下代码放入根视图控制器的 viewDidLoad 中:
通过设置根视图控制器上的导航栏按钮,推送的视图将显示相应的后退按钮。
You need to create a custom button on the navigation controller. Put the following code in the viewDidLoad in your Root View Controller:
By setting the navigation bar button on the Root View Controller, the pushed view shows the appropriate back button.
您可以在推送新视图控制器之前更改导航控制器当前视图控制器的标题:
You can change the title of the current view controller of the navigation controller before push the new view controller:
您实际上可以在主视图控制器的
navigationItem
标题上设置标题。基本上每个UIViewController
都有一个小存根UINavigationItem
,其中包含有关如何在UINavigationController
内引用该视图的元数据。默认情况下,该元数据仅回退到 UIViewController 本身。假设“self”是
UINavigationController
内可见视图的UIViewController
,请设置:You can actually set the title on the main view controller's
navigationItem
's title. Basically eachUIViewController
has a little stubUINavigationItem
which contains metadata about how that view should be referenced inside aUINavigationController
. By default, that metadata just falls back to theUIViewController
itself.Assuming 'self' is the
UIViewController
of the view that's visible inside theUINavigationController
, set:您可以通过在原始控制器的“viewWillDisappear”函数中设置后退按钮标题来实现此目的,如下所示:
You can achieve this by setting the Back button title in the originating controller's "viewWillDisappear" function as follows: