问题描述
我在一个选项卡中有一个UIWebView加载到viewDidLoad中,但是如果用户点击其他选项卡,加载将被中断并且
- (void)webView:(UIWebView *)webView didFailLoadWithError: (NSError *)错误
将被调用,但我想知道如果用户再次点击上一个标签时如何检查是否加载了webView,如果没有加载它将重新加载它,类似这样的
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?
推荐答案
UIWebview有一个webViewDidFinishLoad委托方法。设置一个bool来表明这已经完成。
UIWebview has a webViewDidFinishLoad delegate method. Set a bool to indicate this was done.
- (void)webViewDidStartLoad:(UIWebView *)webView {
webViewDidFinishLoadBool = NO;
loadFailedBool = NO;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
loadFailedBool = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
if (!loadFailedBool)
webViewDidFinishLoadBool = YES;
}
这篇关于检查是否已加载UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!