简体   繁体   English

从SKScene到UIViewController的Segue不起作用

[英]Segue from SKScene to UIViewController doesn't work

The structure of my storyboard: 我的故事板的结构:

1.Screen1 (UIViewController) 1.Screen1(UIViewController)

2.GameScreen (SKScene) 2.GameScreen(SKScene)

3.Screen3 (UIViewController) 3.Screen3(UIViewController)

I'm passing UIViewController self object from Screen1 我正在从Screen1传递UIViewController自对象

//Screen1 class

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

to GameScreen, when making a segue: 进行游戏时,转到GameScreen:

//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: 我的任务是使用Screen1的对象从GameScreen到Screen3进行筛选,该对象已从上一步传递:

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. 一切都应该正常工作,因为我将一个segue从Screen1拖动到Screen3,为其指定了标识符“ toScoreSegue1”,并使用Screen1对象对其进行了调用。 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. 我错误地在错误的ViewController上调用了performSegue。

I had to call segue on ViewController that initialized SKScene view: 我必须在初始化SKScene视图的ViewController上调用segue:

1.Screen1 (UIViewController) 1.Screen1(UIViewController)

2.GameScreen (SKScene) - has its own ViewController, which should be used instead of Screen1! 2.GameScreen(SKScene)-有自己的ViewController,应该使用它代替Screen1!

3.Screen3 (UIViewController) 3.Screen3(UIViewController)

I really hope somebody with same problem may find it helpful. 我真的希望有人遇到同样的问题可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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