我希望我的UIWebView在出现干扰或干扰时显示警报视图错误消息,我已尝试实施以下代码,但未成功:
func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
let myAlert = UIAlertController(title: "Alert", message: error?.localizedDescription, preferredStyle: UIAlertControllerStyle.Alert)
myAlert.showViewController(myAlert, sender: self)
}
这种方法是否有效,如果是,我应该如何纠正呢?
答案 0 :(得分:2)
替换:myAlert.showViewController(myAlert, sender: self)
这样:self.presentViewController(myAlert, animated: true, completion: nil)