In my iPhone application, I’m showing a web page in webview.
I implemented the delegate method as follows:
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error loading the requested URL" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
When ever I open a URL and loaded half page, i’m immediately clicking some other link in the web page. At that time also, this delegate method is being called.
How should I prevent to call delegate method when web page is loaded half and URL link is clicked.
Or some other solution can be to call stopLoading when some URL is clicked. How can I do that?
You can’t really stop the method from being called – but you might be able to check the properties of the
errorobject to determine what kind of error you got.You can use
webView:shouldStartLoadWithRequest:navigationType:which will be called whenever the user takes some kind of navigation action (e.g. clicks a link, submits a form etc. You can usenavigationTypeto determine what the action was). It should be possible to callstopLoadingfrom there (though the webView might still call thewebView:didFailWithError:method, I’m not sure… see the first part on how you can deal with that).