webViewDidStartLoad
and webViewDidFinishLoad
are not working.
What I have already done:
webView.delegate = self;
UIWebViewDelegate
viewDidAppear
. Here is the code:
func webViewDidStartLoad(webView: UIWebView!) {
print("Webview started Loading")
}
func webViewDidFinishLoad(webView: UIWebView!) {
print("Webview did finish load")
}
Check this simple example code which is working fine:
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")
}
}
Update for 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")
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.