0
votes

I have tried several different answers and have yet to find an answer that works.

I keep getting

fatal error: unexpectedly found nil while unwrapping an Optional value

I have a SKScene called selectUpgrade that is in my GameViewController and I am trying to segue to a UIViewController called MissileUpgrade.

var vc2 = MissileUpgrade()  //trying to get to this UIViewController
var gameVC = GameViewController()  // currently in a scene in this UIViewController

I am calling this in my scene to segue

func goToMissileUpgrade() {
    gameVC.presentViewController(vc2, animated: true, completion: nil)
}

These are in the same storyboard. If I set MissileUpgrade as the initial VC it will load fine so I know it has nothing to do on that end. I am lost on why this is not working. Thanks for your help!

1
If you are currently in GameViewController, shouldn't your code be self. presentViewController instead of gameVC.presentViewController?paulvs
I am in a SKScene that is called selectUpgrade so when i do that I get the error "selectUpgrade" has so member "presentViewController"Timmy Sorensen
Ok, what line is it crashing on? Is gameVC or vc2 nil?paulvs
gameVC.presentViewController(vc2, animated: true, completion: nil)Timmy Sorensen

1 Answers

0
votes

If you are using storyboards, don't use presentViewController use performSegueWithIdentifier

Give your Segue an Identifier in the Storyboard, then refer to it in the code like so:

self.performSegueWithIdentifier("yourSegueIdentifierHere", sender: self)