swift - 如何在 Skscene SWIFT 中呈现 UIAlert

标签 swift uialertcontroller

我环顾四周,没有人在 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)

这对我有用。 :)

关于swift - 如何在 Skscene SWIFT 中呈现 UIAlert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32790919/

相关文章:

ios - Swift:UIAlertController 从列表中选择子集

ios - Objective-C 循环比较两个文本字段的密码

swift - iOS 13 UISplitView 问题

swift - 点击 Google 地方信息中的选择后显示 View Controller 的更好方法

ios - Swift 2,无法识别的选择器发送到 UIAlertController 的实例

storyboard - 呈现警报 Controller 时 UIPopOverController 缩小

ios - 如何指定弹出 Controller 的箭头指向的位置

ios - 具有多个单元模板的 CollectionView(使用未声明的类型,<typeName> 对于此上下文中的类型查找是不明确的)

ios - 模块 'Swift' : Permission denied 的导入文件

ios - Swift - UITableView 滚动到底部很慢