简体   繁体   中英

Segue from SKScene to UIViewController doesn't work

The structure of my storyboard:

1.Screen1 (UIViewController)

2.GameScreen (SKScene)

3.Screen3 (UIViewController)

I'm passing UIViewController self object from Screen1

//Screen1 class

@IBAction func onStartButtonClicked(_ sender: Any) {
    Values.viewController = self
}

to GameScreen, when making a segue:

//GameScreen class 

struct Values {
   static var viewController: UIViewController!
}

class GameScreen: SKScene {...}

My task is to make a segue from GameScreen to Screen3 using object of Screen1, which has been passed from previous step:

Values.viewController!.performSegue(withIdentifier: "toScoreSegue1", sender:  self)

Everything should work fine, since I dragged a segue from Screen1 to Screen3, gave it identifier "toScoreSegue1" and calling it using Screen1 object. However, nothing happens.

There is no error etc.

Any help would be highly appreciated!

I figured out a problem!

By mistake, I called performSegue on wrong ViewController.

I had to call segue on ViewController that initialized SKScene view:

1.Screen1 (UIViewController)

2.GameScreen (SKScene) - has its own ViewController, which should be used instead of Screen1!

3.Screen3 (UIViewController)

I really hope somebody with same problem may find it helpful.

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