I have a following class:
class HomeViewController: UIViewController {
override func viewdidload() {
super.viewdidload()
callOtherVC()
}
func callOtherVC() {
let viewController = StepsViewController()
let rootViewController = UINavigationController(rootViewController: viewController)
self.presentViewController(rootViewController, animated: true, completion: nil)
}
}
StepsViewController is just another viewcontroller. In StepsViewController, I try to dismiss current StepsViewController and present other viewcontroller. Following is code.
class StepsViewController: UIViewController {
override func viewdidload() {
super.viewdidload()
callSecondOtherVC()
}
func callSecondOtherVC() {
let vc = ViewController()
self.addChildViewController(vc)
self.parentViewController!.dismissViewControllerAnimated(true, completion: nil)
vc.callOtherVC()
}
}
I initialize ViewController()
because I need to call same function callOtherVC
from ViewController. Basically the model in ViewController changes but I'm essentially calling same UINavigationController from callOtherVC
function.
Whenever I do this, I get an error like below:\
Warning: Attempt to present (UINavigationController: 0x7d991600) on (HomeViewController: 0x7a6e00a0) whose view is not in the window hierarchy!
UINavigationController
is from callSecondOtherVC
and HomeViewController
is as it is.
How should I order the VCs? And if someone can more explain about the view hierarchy, I would greatly appreciate.