我正在为一个 class 制作一个简单的hangman游戏,并且我试图在用户赢/输游戏时显示UIAlert。我尝试按照此处概述的方法进行UIAlertController初始化:https://developer.apple.com/documentation/uikit/uialertcontroller
我已经尝试完全按照他们的方式进行操作(甚至将粘贴的示例代码复制到我的方法中以查看其是否有效,但我遇到了同样的错误):
let winAlert = UIAlertController(title: "You won!", message: "Go bears!", preferredStyle: .alert)
这给我一个错误:“表达式的类型是模棱两可的,没有更多的上下文”。我能做什么?
编辑
修复了帖子中的错字。
另外,如果我尝试将最后一个字段PreferredStyle从
.alert
更改为UIAlertController.Style.alert
,则会收到错误警告:“UIAlertController没有成员样式”,即使文档指出它具有名为Style的枚举?
最佳答案
您已经编写了 UIControllerAlert 。尝试使用 UIAlertController 。同样不要忘记导入UIKit。
let winAlert = UIAlertController(title: "You won!", message: "Go bears!", preferredStyle: .alert)
关于ios - 试图使UIAlertController似乎无法初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60626067/