1

此 Web 视图失败错误,即使在加载网站时也会显示警报弹出窗口。我相信我需要延迟此方法才能使其起作用。这样做的最佳方法是什么?

- (void)webView:(UIWebView *)webViewfail didFailLoadWithError:(NSError *)error 
{
    if([webViewfail isEqual:webview]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed" message:@"Check your Internet connection before refreshing."
                                                   delegate:webview
                                          cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
}

这是我加载网站的方式

- (void)viewDidLoad
{
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL    URLWithString:@"http://www.blabla.com"]]];
}
4

1 回答 1

1

问题很可能是错误 -999,通常在网页中的某些内容未正确加载或用户在页面仍在加载时尝试返回时发生。经过一些研究,这是我发现并用来防止 NetworkAlert 每次都弹出但在没有网络时仍会弹出的内容。

-(void)webView:(UIWebView *)webBlog didFailLoadWithError:(NSError *)error{

if ([error code] != -999) {
    NSLog(@"Could not load the dumb webPage");
    //show error alert, etc.
    [self showNoNetworkAlert];
   }else{

NSLog(@"Could not load the dumb web page...just might blame user!");
    }
}

- (void) showNoNetworkAlert{
UIAlertView *baseAlert = [[UIAlertView alloc]
                          initWithTitle:@"No Network"     message:@"A network connection is required.  Please verify your network settings and try again."
                          delegate:nil cancelButtonTitle:nil
                          otherButtonTitles:@"Dismiss", nil];
[baseAlert show];
}

希望这可以帮助某人...

于 2013-05-09T18:41:50.083 回答