I am trying to build a storyboard in Xcode 7.x with more than 4 consequtive view controllers embedded in a UINavigationController. The navigation controller is the initial view controller. Embedded is a simple view controller only containing a single button, which is connected to an Adaptive Show Segue, calling a similar view controller and so on. Each one calling the next by a simple Show Segue. The Push only works for 3 consecutive calls, thereafter the reference to the navigation controller is lost. The 5th view controller and on are presented modally.
I am having this problem in different project at least since iOS 8.
Is the UINavigationController viewControllers stack limited to 4 entries?
More than 4 view controllers embedded in an UINavigationController
The code of the embedded view controllers:
class ViewController: UIViewController {
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
print("ViewCintroller:\(title) NavController:\(navigationController) stack size:\(navigationController?.viewControllers.count)")
print()
}
}
output:
ViewController:Optional("V1") NavController:Optional(<UINavigationController: 0x7fd57b024200>) stack size:Optional(1)
ViewController:Optional("V2") NavController:Optional(<UINavigationController: 0x7fd57b024200>) stack size:Optional(2)
ViewController:Optional("V3") NavController:Optional(<UINavigationController: 0x7fd57b024200>) stack size:Optional(3)
ViewController:Optional("V4") NavController:Optional(<UINavigationController: 0x7fd57b024200>) stack size:Optional(4)
ViewController:Optional("V5") NavController:nil stack size:nil
ViewController:Optional("V6") NavController:nil stack size:nil
changing all segues to the deprecated push type leads to the required result:
ViewController:Optional("V1") NavController:Optional(<UINavigationController: 0x7fc8a1026200>) stack size:Optional(1)
ViewController:Optional("V2") NavController:Optional(<UINavigationController: 0x7fc8a1026200>) stack size:Optional(2)
ViewController:Optional("V3") NavController:Optional(<UINavigationController: 0x7fc8a1026200>) stack size:Optional(3)
ViewController:Optional("V4") NavController:Optional(<UINavigationController: 0x7fc8a1026200>) stack size:Optional(4)
ViewController:Optional("V5") NavController:Optional(<UINavigationController: 0x7fc8a1026200>) stack size:Optional(5)
ViewController:Optional("V6") NavController:Optional(<UINavigationController: 0x7fc8a1026200>) stack size:Optional(6)
Edit:
In my opinion, the problem is with interface builder. I got a working solution with changing all show segues to push segues, compiling, changing the push segues back to show segues, compiling again and the anomaly is gone. The navigation stack isn't limited any more to 4 view controllers.