Jef*_*ski 3 swift uialertcontroller
在以下代码中,当我的Web视图无法加载时,正如预期的那样,使用"重试"按钮正确显示警报.点击"重试"按钮时警报会消失,但永远不会调用完成.为什么是这样?
func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
let alert = UIAlertController(title: "Network Error", message: "There was a error loading the page.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Retry", style: .default, handler: { _ in
alert.dismiss(animated: true, completion: {
self.webView.loadHTMLString("Reloaded", baseURL: nil)
})
}));
self.present(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
不要alert.dismiss在警报行动中打电话.当用户点击其中一个警报按钮时,警报控制器将自动关闭.
您只需要:
alert.addAction(UIAlertAction(title: "Retry", style: .default, handler: { _ in
self.webView.loadHTMLString("Reloaded", baseURL: nil)
}))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1041 次 |
| 最近记录: |