0
votes

My view hierarchy looks like image below:enter image description here

My problem is I want to show VC1 when I click any button on VC3. Here is my code

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("registerNavigation")
self.presentViewController(vc, animated: false, completion: nil)

but I got this warning "Warning: attempt to present ViewController whose view is not in the window hierarchy" and nothing happen. Please tell me, what did I do wrong?

2
hello dear kindly have a look of this article hope this completely solve your problem and understands the root of warning which you are getting ..vaibhav

2 Answers

2
votes

If you want to show VC1 from VC3 the you not need to present it again because it is already loaded in navigation stack. you just need to dismiss or pop VC3 and VC2 from navigation stack. If you have presented it then dismiss and if you have pushed it then popped it.

Your warning's meaning : you are trying to presenting which is in the view hierarchy of navigation controller 1 but not in the view hierarchy of navigation controller 2.!!

Hope this will help :)

0
votes

You are presenting to navigationController so use code like below.

let VC1 = self.storyboard!.instantiateViewControllerWithIdentifier("registerNavigation") as! ViewController
let navController = UINavigationController(rootViewController: VC1)
self.presentViewController(navController, animated:true, completion: nil)