如何正确实现UIWebView' didFailLoadWithError'警报视图?

时间:2015-09-21 19:24:00

标签: ios swift error-handling uiwebview

我希望我的UIWebView在出现干扰或干扰时显示警报视图错误消息,我已尝试实施以下代码,但未成功:

func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
        let myAlert = UIAlertController(title: "Alert", message: error?.localizedDescription, preferredStyle: UIAlertControllerStyle.Alert)
         myAlert.showViewController(myAlert, sender: self)
    }

这种方法是否有效,如果是,我应该如何纠正呢?

1 个答案:

答案 0 :(得分:2)

替换:myAlert.showViewController(myAlert, sender: self)

这样:self.presentViewController(myAlert, animated: true, completion: nil)