iPhone : webView:shouldStartLoadWithRequest:navigationType timing problem
I have a WebView which is loading and HTML String and I want it to catch clicks on links. For that I need to use the webView:shouldStartLoadWithRequest:navigationType method. The problem is that this method gets called multiple times before the HTML content is fully loaded and I only want to start catching clicks at that moment. The question is how to know when the HTML content is fully loaded ? I thought it was simple so I created a boolean as an iVar of the ViewController containing the WebView and I set it to YES after calling loadHTMLString. Then, in webView:shouldStartLoadWithRequest:navigationType I was testing if that boolean was true and if it was the case I was outputting something like "OK". But "OK" was appearing without clicking on a link => fai开发者_如何学运维l.
Any idea on how I could make this work ?
Thanks in advance
You could use the webViewDidFinishLoad:
delegate method to know when the HTML is loaded.
But I'd rather use another solution:
In webView:shouldStartLoadWithRequest:navigationType:
you can filter requests by navigation type:
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
// Catch links
return NO; // if you want to cancel the request, else YES
}
- (void)webViewDidFinishLoad:(UIWebView *)webViews{
}
this method will callwhen the HTML content is fully loaded. it may helps you.
精彩评论