I try to open a second view controller in one func but this error appears:
Attempt to present
<UINavigationController>
on firstController whose view is not in the window hierarchy!
All solutions required :
Either put code inside viewWillAppear()
or inside IBAction
func
My program requires to open the second view controller from normal func
I tried all this codes:
Code1:
self.performSegueWithIdentifier("page2", sender:self)
result:
error: has no segue with identifier 'page2''
Code 2:
let secondViewController:page2 = page2()
self.presentViewController(secondViewController, animated: true,completion: nil)
result:
error: whose view is not in the window hierarchy!
Code 3:
let nextViewController = storyboard!.instantiateViewControllerWithIdentifier("next2") as! UIViewController
self.presentViewController(nextViewController, animated:true, completion:nil)
result:
fatal error: unexpectedly found nil fwom win func
Code 4:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("next2") as! page2
self.presentViewController(nextViewController, animated:true, completion:nil)
dismissViewControllerAnimated(true, completion:nil)
result:
error whose view is not in the window hierarchy!
I need a solution please.
viewWillAppear()
is called before the view controller's view is about to be added to a view hierarchy. – esesmuedgars