我试图了解如何从URL创建一个Webview,以了解它何时开始加载以及何时完成。 使用以下代码
class WebsiteViewController: UIViewController, UIWebViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
loadWebPage()
}
func loadWebPage(){
let theURL = "https://www.example.com/"
let theRequestURL = NSURL (string: theURL)
let theRequest = NSURLRequest (URL: theRequestURL!)
webView.delegate = self
webView.loadRequest(theRequest)
}
func webViewDidStartLoad(webView : UIWebView) {
//UIApplication.sharedApplication().networkActivityIndicatorVisible = true
print("Started")
}
func webViewDidFinishLoad(webView : UIWebView) {
//UIApplication.sharedApplication().networkActivityIndicatorVisible = false
print("Finished")
}
}
我有这些打印结果
Started
Started
Finished
Finished
Started
Finished
Started
Finished
Finished
知道为什么吗?