簡體   English   中英

為什么我的警報視圖控制器不起作用

[英]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() }))

如果我對此進行構建,則不會出現警報視圖。 我錯過了什么?

附言:我知道也有類似的問題,但是要弄清他們所擁有的和我錯過的是很難的

您必須在視圖上顯示警報視圖。

self.present(alert, animated: true, completion: nil)

您還需要在當前上下文中展示它:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM