2

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.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Wayne Henderson
  • 237
  • 3
  • 9
  • OK, it looks like the warning was from having the button defined as both a segue trigger and as a coded button. I eliminated the segue trigger, left the function code, and the warning went away. But now the problem is that the segue is not performed when the button's function is called from within viewDidLoad for Main. I have Print statements in there for debugging and those all print, but the segue doesn't happen. No warnings or errors, just nothing. – Wayne Henderson Jan 07 '16 at 04:21
  • Adding a 1 second delay before calling for the segue cured the problem. I used the dispatch_after method mentioned in http://stackoverflow.com/questions/27517632/how-to-create-a-delay-in-swift – Wayne Henderson Jan 07 '16 at 04:47

1 Answers1

3
self.navigationController?.pushViewController(nextViewController, animated: true)
Sam
  • 145
  • 1
  • 15