Swift 2 Webview加载代理功能

时间:2016-09-06 11:13:28

标签: ios swift uiwebview swift2 uiwebviewdelegate

我试图了解如何从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

知道为什么吗?

0 个答案:

没有答案