webViewDidStartLoad 不工作

webViewDidStartLoad not working

webViewDidStartLoadwebViewDidFinishLoad 不工作。

我已经做过的事情:

  1. webView.delegate = self;
  2. 已添加UIWebViewDelegate
  3. 将代码放在 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")
}

}