【发布时间】:2017-08-06 09:53:37
【问题描述】:
我没有发现我的代码有什么问题。我只是用“确定”按钮显示警报,当用户单击“确定”时,警报应该会消失。但它并没有消失。使用 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)
}
更新:
当我将相同的代码放在其他控制器中时,它起作用了。
在原始控制器中,在 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(),只是为了设置屏幕标题。
【问题讨论】:
-
你的代码很好,很正确,对我来说也很完美
-
奇怪。它不适合我。 :(
-
清理并运行一次
-
:( ....还是不行
-
@UmarFarooque 两件事:(1)不要在标题中添加标签;这就是标签部分的用途。其次,如果您提出修改建议,请尝试修复帖子中的所有 问题 - 或者至少不要只是在标题中移动内容。谢谢,希望能见到你! :)
标签: ios swift3 uialertcontroller viewdidappear