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?
For pages with multiple frames, UIWebView.loading property should also be used.
Apple's doc: @property(nonatomic, readonly, getter=isLoading) BOOL loading A Boolean value indicating whether the receiver is done loading content.
If YES, the receiver is still loading content; otherwise, NO.
In iOS6 (beta 4) it looks like Apple has fixed some issues with this property as well. http://code-gotcha.blogspot.fi/2012/08/uiwebviewloading-in-ios-6-fixed.html
If you haven't got it to work yet, here is a working example. It also shows an alert when failing to load, and the alert is only shown once.
Header:
Implementation:
I hope that helps.
UIWebview has a webViewDidFinishLoad delegate method. Set a bool to indicate this was done.
It is true that the original question was posted many years ago. Recently I had to find a reliable solution to this issue.
Here is the solution that worked for me:
The complete code is: