iosswiftuinavigationcontrollerpushviewcontroller

Missing Navigation's or Back Button's Title When Push ViewControllers in Succession


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

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

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

User manually push the controller by tapping on tableview's cell

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

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

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

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):

enter image description here

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?

Thanks in advance.


Solution

  • 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
    }