Determinate finish loading website in webView with Swift in Xcode

Mirko Brombin picture Mirko Brombin · Jan 26, 2015 · Viewed 18.7k times · Source

i'm trying to create a webapp with swift in xcode, this is my current code:

IBOutlet var webView: UIWebView!

    var theBool: Bool = false
    var myTimer = NSTimer()
    @IBOutlet var progressBar: UIProgressView!

override func viewDidLoad() {
   super.viewDidLoad()
   let url = NSURL(string: "http://stackoverflow.com")
   let request = NSURLRequest(URL: url)
   webView.loadRequest(request)
}

I've a question, How i can determinate the finish loading of the page in webView?

Do you know a documentation that contains all the definitions of the WebView? I mean .. (start / end load, the current url, title page, etc ..)?

(Sorry for my English).

Answer

Marius Fanu picture Marius Fanu · Jan 26, 2015

Through the UIWebView delegate call.

You need to set your webViews delegate to the current controller, and conform to the UIWebViewDelegate protocol. When the webView finished loading the page func webViewDidFinishLoad(_ webView: UIWebView) will get called.