UIWebView, determine if the page is loaded

I would like to know when my webview finished loading the page. I am completely new to this, and I wonder if you have any suggestions. I need to create a “Screen Download” at the time the page loads. This is my main 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];
}

Thank!

+3
source share
3 answers

There are two different callbacks when the view finishes loading, successful loading and load loss. They are part of the UIWebViewDelegate protocol .

Deploy it and establish yourself as a delegate for your web view. Then do

- (void)webViewDidFinishLoad:(UIWebView *)webView

Know when the download is complete so that you can remove the download screen and implement

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

, , .

+8

UIWebViewDelegate Protocoll. , – webViewDidFinishLoad:

, ?

+3

DOM, , document.readyState - .

w3schools:

readyState () .

:

uninitialized - - interactive - complete -

, , , UIWebView :

- (void)readyState:(NSString *)str
{ NSLog(@"str:%@",str);

if ([str isEqualToString:@"complete"]||[str isEqualToString:@"interactive"]) {
    NSLog(@"IT HAS BEEN DONE");
    [pageLoadingActivityIndicator stopAnimating];
}

}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
 //other code...
 [self readyState:[browserWebView stringByEvaluatingJavaScriptFromString:str]];
}
0

All Articles