连续推送 ViewController 时缺少导航或后退按钮的标题 [英] Missing Navigation's or Back Button's Title When Push ViewControllers in Succession

查看:22
本文介绍了连续推送 ViewController 时缺少导航或后退按钮的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在连续推送视图控制器时,UINavigationController 出现问题.

I have a problem on UINavigationController when pushing view controllers in succession.

有关信息,我使用 XCode 7.0,针对 iOS 8 构建,以及在 Simulator 9.0 上运行的应用程序.

For information, I use XCode 7.0, build targeting iOS 8, and the app running on Simulator 9.0.

这是用户手动点击 tableview 的单元格时的视图:

Here's the view when user manually tap the tableview's cell:

如上图所示,导航和后退按钮的标题呈现正常.

As shown on the above screenshots, the navigation's and back button's title were rendered normally.

但是当我以编程方式执行此操作时,就像这样(stackUIViewController 的数组):

But when I did this programmatically, like this (stack is array of UIViewController):

for controller in stack {
    self.mainNavController.pushViewController(controller, animated: false)
}

或者像这样使用 0.0 秒的延迟:

or using delay on 0.0 second like this:

for controller in stack {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64((0.0 * Float(NSEC_PER_SEC)))), dispatch_get_main_queue(), {
        self.mainNavController.pushViewController(controller, animated: false)
    })
}

它会显示这样的最终结果(左边是无延迟,右边是有延迟):

It will show the final result like this (left is w/o delay, right is w/ delay):

请注意左侧屏幕截图上缺少导航标题(无延迟)和右侧屏幕截图上缺少后退按钮标题(无延迟).

Notice the missing navigation title on the left screenshot (w/o delay) and missing back button title on the right screenshot (w/ delay).

这个问题让我困惑了好几天.知道为什么会这样吗?有谁知道如何解决这一问题?或者至少,解决这个问题?

This issue has confuse me for days. Any idea of why this is happening? Does anyone know how to fix this? Or at least, work around this issue?

提前致谢.

推荐答案

这就是我过去所做的.您可能会发现它很有帮助:

This is what I have done in the past. You might find it helpful:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let myBackButton = UIBarButtonItem()
    myBackButton.title = "This is my back button"
    navigationItem.backBarButtonItem = myBackButton
}

这篇关于连续推送 ViewController 时缺少导航或后退按钮的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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