简体   繁体   中英

webViewDidStartLoad not working

webViewDidStartLoad and webViewDidFinishLoad are not working.

What I have already done:

  1. webView.delegate = self;
  2. added UIWebViewDelegate
  3. placed the code in 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM