NGR*_*NGR 6 viewdidappear ios uialertcontroller swift3
我没有弄到我的代码有什么问题.我只是用"确定"按钮显示警报,当用户点击"确定"时,警报就应该开始.但它并没有消失.使用Swift3进行编程.viewDidAppear()这个代码是正确的地方吗?或者我做错了什么?
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)
}
Run Code Online (Sandbox Code Playgroud)
更新:当我将相同的代码放在其他控制器中时,它工作.在原始控制器中,在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
}
})
}
Run Code Online (Sandbox Code Playgroud)
我还覆盖viewWillDisappear()和viewWillAppear(),只需设定屏幕的标题.
我在警报代码之前添加以下代码viewDidAppear(),它开始工作。我在两个位置都保留了以下代码,即在Async通话中和在viewDidAppear()
self.activityIndicator.stopAnimating()
UIApplication.shared.endIgnoringInteractionEvents()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
628 次 |
| 最近记录: |