0

I'm needing help with this answer from UIWebView - How to identify the "last" webViewDidFinishLoad message?

How would I declare webViewLoads_++; and webViewLoads_--; in the following code:

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


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

 if (webViewLoads_ > 0) {
return;
}

 …
}

Thanks

Community
  • 1
  • 1
0SX
  • 1,252
  • 6
  • 24
  • 47

3 Answers3

1

Should be in instance variable of type int: int webViewLoads_; in the .h file.

Eiko
  • 25,601
  • 15
  • 56
  • 71
1

The simplest way is to declare an int in your .m (implementation) file, above webViewDidStartLoad::

int webViewLoads_ = 0;

Remember to reset this to 0 when the last load completes:

webViewLoads_--;
if (webViewLoads_ > 0)
{
    return;
}
webViewLoads_ = 0;
Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
0

You can tell when a webview is really "done" by using the delegate method:

webView:didFinishLoadForFrame:
ExitToShell
  • 460
  • 4
  • 14
  • I know this is a noob question but where would I put that? Would I just do this: - (void) didFinishLoadForFrame:(UIWebView *)webView{ – 0SX Jan 17 '11 at 00:44
  • @Alan, That could be the reason why I've never seen that in the iOS Docs. ;-) – 0SX Jan 17 '11 at 00:48
  • Yep, the UIKit WebView (UIWebView) has only but a subset of what is provided to developers targeting OS X. – Alan Zeino Jan 17 '11 at 00:50