我不明白我的代碼有什麼問題。我只是用「Ok」按鈕顯示一個提醒,當用戶點擊「確定」時,然後提醒。但它並沒有消失。使用Swift3進行編程。 viewDidAppear()
是否可以放這個代碼?或者我做錯了什麼?UIAlertController不會消失
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let alertController = UIAlertController(title: "Wrong Item", message: "Could not find details of an item.", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(alertController, animated: true, completion: nil)
}
UPDATE: 當我把在其他控制器相同的代碼,它的工作。 在原控制器中,在viewDidLoad(),我有一個Async
調用如下。這是因爲這個問題嗎?
DispatchQueue.global(qos: .background).async {
self.getDetails(onCompletion: {(json: JSON) in
let dict = self.convertToDictionary(text: json.stringValue)
DispatchQueue.main.async {
self.activityIndicator.stopAnimating()
UIApplication.shared.endIgnoringInteractionEvents()
//Other UI update operation
}
})
}
我也覆蓋viewWillDisappear()
和viewWillAppear()
,只需設定屏幕的標題。
你的代碼是好的,正確的,以及它完美的我 –
奇怪的工作。這不適合我。 :( – NGR
清理並運行一次 –