webViewDidStartLoad 不工作
webViewDidStartLoad not working
webViewDidStartLoad
和 webViewDidFinishLoad
不工作。
我已经做过的事情:
webView.delegate = self;
- 已添加
UIWebViewDelegate
- 将代码放在
viewDidAppear
。
代码如下:
func webViewDidStartLoad(webView: UIWebView!) {
print("Webview started Loading")
}
func webViewDidFinishLoad(webView: UIWebView!) {
print("Webview did finish load")
}
检查这个工作正常的简单示例代码:
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = "http://apple.com"
let requestURL = NSURL(string:url)
let request = NSURLRequest(URL: requestURL!)
webView.delegate = self
webView.loadRequest(request)
}
func webViewDidStartLoad(webView: UIWebView) {
print("Webview started Loading")
}
func webViewDidFinishLoad(webView: UIWebView) {
print("Webview did finish load")
}
}
更新 Swift 3
let url = "http://apple.com"
let requestURL = URL(string:url)
let request = URLRequest(url: requestURL!)
webView.delegate = self
webView.loadRequest(request)
}
func webViewDidStartLoad(_ webView: UIWebView) {
print("Webview started Loading")
}
func webViewDidFinishLoad(_ webView: UIWebView) {
print("Webview did finish load")
}
}
webViewDidStartLoad
和 webViewDidFinishLoad
不工作。
我已经做过的事情:
webView.delegate = self;
- 已添加
UIWebViewDelegate
- 将代码放在
viewDidAppear
。
代码如下:
func webViewDidStartLoad(webView: UIWebView!) {
print("Webview started Loading")
}
func webViewDidFinishLoad(webView: UIWebView!) {
print("Webview did finish load")
}
检查这个工作正常的简单示例代码:
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = "http://apple.com"
let requestURL = NSURL(string:url)
let request = NSURLRequest(URL: requestURL!)
webView.delegate = self
webView.loadRequest(request)
}
func webViewDidStartLoad(webView: UIWebView) {
print("Webview started Loading")
}
func webViewDidFinishLoad(webView: UIWebView) {
print("Webview did finish load")
}
}
更新 Swift 3
let url = "http://apple.com"
let requestURL = URL(string:url)
let request = URLRequest(url: requestURL!)
webView.delegate = self
webView.loadRequest(request)
}
func webViewDidStartLoad(_ webView: UIWebView) {
print("Webview started Loading")
}
func webViewDidFinishLoad(_ webView: UIWebView) {
print("Webview did finish load")
}
}