我从API获取URL,正在将该URL传递到Webview并尝试加载,但未加载。我不知道为什么,但是它不起作用。即使没有显示任何错误或崩溃。太奇怪了,但是我不知道我缺少什么,因为所有代码都写得很好。这是我的代码:
self.loadWeb(webURL: newsUrl!)
func loadWeb(webURL: String) {
let url = URL(string: webURL)
MBProgressHUD.hide(for: self.view, animated: true)
webView.navigationDelegate = self
webView.uiDelegate = self
webView.load(URLRequest(url: url!))
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.frame.size.height = 1
webView.scrollView.isScrollEnabled = false
webView.frame.size = webView.scrollView.contentSize
self.bgViewHeight.constant = webView.frame.size.height
}
private func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
print(error.localizedDescription)
}
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
print("Start to load")
}
func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
print("finish to load")
}
我该如何加载?