Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if UIWebView is loaded

I have an UIWebView in one tab that loads in viewDidLoad, but if user taps other tab the loading will be disrupted and - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error will be called, but I want to know how can check if webView is loaded if user taps the previous tab again, and if it's not loaded it will reload it, something like this

  -(void)viewWillAppear:(BOOL)animated
{
    if (!webView)
        {
          NSURL *url = [NSURL URLWithString:@"url"];
          NSURLRequest *request = [NSURLRequest requestWithURL:url];
          [webView loadRequest:request];
        }

    }

But it's not working, help please?

like image 652
vburojevic Avatar asked Oct 05 '11 20:10

vburojevic


1 Answers

UIWebview has a webViewDidFinishLoad delegate method. Set a bool to indicate this was done.

- (void)webViewDidStartLoad:(UIWebView *)webView {

 webViewDidFinishLoadBool = NO;
 loadFailedBool = NO;

}


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

 loadFailedBool = YES;
}


- (void)webViewDidFinishLoad:(UIWebView *)webView {

   if (!loadFailedBool)
   webViewDidFinishLoadBool = YES;

}
like image 92
Zigglzworth Avatar answered Oct 13 '22 07:10

Zigglzworth