简体   繁体   中英

How to perform a successful segue programmatically from SKScene to UIViewController

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM