我正在尝试编写一个函数,当一个UIAlertController
空时显示一个UITextField
。我使用下面的example来显示消息。在这个阶段,我得到以下错误:
未解析标识符'self‘的使用
下面是我的代码。
func displayMyAlertMessage(userMessage: String){
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertController.Style.alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: nil)
myAlert.addAction(okAction)
self.present(myAlert, animated: true, completion: nil)
}
发布于 2019-04-21 20:41:35
问题可能是您的func
不在任何UIViewController子类声明中。因此没有self
(或者self
不是视图控制器,所以没有self.present
)。
https://stackoverflow.com/questions/55785836
复制相似问题