Reputation: 267
My question is very much like these two:
EXCEPT that my segue is to a Navigation Controller, like this: Main->NC->VC2>VC3
.
The segue from Main to VC2 works fine when I trigger it with a button in my first view controller. It does not work when the segue is called by code. I need to have the segue triggered automatically in response to certain conditions determined by the code in Main.
When the button is linked to a function coded in Main, it still works. Code in the button function definition runs and the segue occurs. When I try to trigger the segue in the code for the function, using
performSegueWithIdentifier("showHelp", sender: nil)
or
performSegueWithIdentifier("showHelp", sender: self)
I get an error:
Warning: Attempt to present <UINavigationController: 0x7fc8e1043000> on <myApp.Main: 0x7fc8e0d17b10> whose view is not in the window hierarchy!
The button continues to trigger the segue, despite the warning, but not when the button's function is called by other code.
Upvotes: 2
Views: 2047
Reputation: 145
self.navigationController?.pushViewController(nextViewController, animated: true)
Upvotes: 3