UIWebView, determine if page has loaded
iphone, objective-c, xcode
Solution
There are two different callbacks when the view finishes loading, successful load and failed load. They are both part of the the UIWebViewDelegate protocol.
Implement it and set yourself as the delegate for your web view. Then implement
- (void)webViewDidFinishLoad:(UIWebView *)webView
to know when the loading has finished, so that you can remove your loading screen, and implement
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
to know if it failed so that you can show and appropriate message to the user instead of an infinite loading screen.
Problem
I would like to know when my WebView has finished loading a page. Im quite new to this and I wonder if you have any suggestions. I need to create a "Loading screen" while the page is loading. This is my basic code: ``` - (void)viewDidLoad { NSString *urlAddress = @"http://google.se"; //Create a URL object. NSURL *url = [NSURL URLWithString:urlAddress]; //URL Requst Object NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; //Load the request in the UIWebView. [webView loadRequest:requestObj]; } ``` Thanks!