如何在 Skscene 中呈现 UIAlert SWIFT

How present a UIAlert in a Skscene SWIFT

我环顾四周,Swift 中没有人有这个答案,所以就在这里。我收到一条错误消息,提示游戏场景中没有名为 presentViewController.

的成员
var alertController = UIAlertController(title: "Nothing Selected",
                                      message: "You have not selected a picture.",
                               preferredStyle: UIAlertControllerStyle.Alert)    
alertController.addAction(UIAlertAction(title: "Dang!",
                                        style: UIAlertActionStyle.Cancel,
                                      handler: nil))
self.presentViewController(alertController, 
                           animated: true, 
                         completion: nil)

在你的最后一行代码中,而不是

self.presentViewController(alertController, animated: true, completion: nil)

尝试

self.view?.window?.rootViewController?.presentViewController(alertController, animated: true, completion: nil)

这对我有用。 :)