[英]Why doesn't my alert view controller work
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() }))
If I build this the alert view doesn't appear. 如果我对此进行构建,则不会出现警报视图。 What have I missed?
我错过了什么?
PS I know there are some similar question but to find out what they have and I have missed is hard 附言:我知道也有类似的问题,但是要弄清他们所拥有的和我错过的是很难的
您必须在视图上显示警报视图。
self.present(alert, animated: true, completion: nil)
You need to present it too on your current context: 您还需要在当前上下文中展示它:
self.present(alert, animated: true, completion: nil)
Add that row at the end of your alert
declaration: 在
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.