2016-01-18 57 views
0

webViewDidStartLoadwebViewDidFinishLoad無法正常工作。webViewDidStartLoad無法正常工作

我已經這樣做:

  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") 
     } 
+0

顯示 您的完整代碼與請求。這將有所幫助。 –

+0

也許你沒有在你的課堂上保留對你的'webView'的引用。 –

回答

1

更新斯威夫特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") 
} 

}

4

檢查這個簡單的例子代碼是工作的罰款:

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") 
    } 
} 
+0

作品!謝謝 – system21

+0

高興地幫助你.. :) –