[英]How to perform a successful segue programmatically from SKScene to UIViewController
我嘗試了幾種不同的答案,但尚未找到有效的答案。
我不斷
fatal error: unexpectedly found nil while unwrapping an Optional value
我的GameViewController中有一個名為selectUpgrade的SKScene,我試圖選擇一個名為MissileUpgrade的UIViewController。
var vc2 = MissileUpgrade() //trying to get to this UIViewController
var gameVC = GameViewController() // currently in a scene in this UIViewController
我在現場叫這個叫
func goToMissileUpgrade() {
gameVC.presentViewController(vc2, animated: true, completion: nil)
}
這些都在同一情節提要中。 如果我將MissileUpgrade設置為初始VC,它將可以很好地加載,因此我知道這方面沒有任何關系。 我不知道為什么這不起作用。 謝謝你的幫助!
如果您使用的是故事板,請不要使用presentViewController
使用performSegueWithIdentifier
在情節提要中為您的Segue提供一個標識符,然后在代碼中引用它,如下所示:
self.performSegueWithIdentifier("yourSegueIdentifierHere", sender: self)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.