let alert = UIAlertController(title: "Title", message: "message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Title", style: UIAlertActionStyle.default, handler: { action in self.alertFunc() }))
如果我构建此代码,则不会显示警报视图。我错过了什么?
P.S。我知道有一些类似的问题,但要找出他们有什么,我错过了很难
答案 0 :(得分:2)
您必须在视图上显示提醒视图。
self.present(alert, animated: true, completion: nil)
答案 1 :(得分:2)
您还需要在当前环境中展示它:
self.present(alert, animated: true, completion: nil)
在alert
声明的末尾添加该行:
let alert = UIAlertController(title: "Title", message: "message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Title", style: UIAlertActionStyle.default, handler: { action in
self.alertFunc()
}))
self.present(alert, animated: true, completion: nil)