Search code examples
iosswiftuinavigationcontroller

UINavigationController.set​View​Controllers is resulting in an empty viewControllers array


I am using the set​View​Controllers function on UINavigationController to set my first root view controller but the viewControllers array is empty after it has been called.

I know it is expected behavior to see the view controller in the viewControllers array immediately after setting, even if there is an animation so I'm not sure what could be causing the problem.

setViewControllers([viewControllerToPresent], animated: true)

Noteworthy: It is happening at app launch time but after I am certain the UINavigationController is loaded and ready.


Solution

  • The problem ended up being trying to simultaneously present a viewcontroller modally (tutorial slides) as the navigationcontroller was trying to push a viewcontroller on to the stack (both animated)

    By delaying the presentation of the modals by 1 second, both view controllers were able to present without clobbering one another.

    Would love to know the whys of this if anyone if familiar enough with UIKit and Animation APIs to explain. Will accept my own answer if I don't hear from anyone but will gladly change this if we get a better answer in the future.