[英]Application doesn't show Alert View Controller?
我有一個應在viewDidLoad()函數中打開Alert View Controller的應用程序。 這是一個簡單的提醒應用程序。 這是一段代碼:
let alert = UIAlertController(title: "Reminder", message: "Your reminder text", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Sure!", style: UIAlertActionStyle.default) {
(finished) in
self.didReceiveRemoteNotificationAction()
})
self.present(alert, animated: true, completion: nil)
但是問題是:它沒有顯示出來! 誰能向我解釋為什么?
我確實知道我的情節提要非常……與觀點交織在一起。 但這不應該是一個問題,對嗎?
這是因為您是從ViewDidLoad調用它的,因此尚未設置視圖! 您有兩種選擇:
使用GCD線程調用它:
DispatchQueue.main.async {self.present(提示,動畫:true,完成:nil)}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.