UIWebView – How to identify the “last” webViewDidFinishLoad message?

I’m guessing that iframes cause the webViewDidStartLoad / webViewDidFinishLoad pair.

The [webView isLoading] check mentioned as an answer didn’t work for me; it returned false even after the first of two webViewDidFinishLoad calls. Instead, I keep track of the loading as follows:

- (void)webViewDidStartLoad:(UIWebView *)webView {
  webViewLoads_++;
}


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

  if (webViewLoads_ > 0) {
    return;
  }

  …
}

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

(Note this will only work if the start / finished pairs don’t come serially, but in my experience so far that hasn’t happened.)

Leave a Comment