我有一个带有标准视图控制器的应用程序,上面有多个按钮。每个按钮都链接到具有唯一 UIWebView 的单独视图控制器。每个 UIWebView 都实现了 didFailLoadWithError 并且似乎工作正常:当我关闭 wifi 并尝试从主视图控制器页面加载 UIWebView 时,我正确地从 didFailLoadWithError 得到错误消息。当我打开 wifi 并加载 UIWebView 时,它工作正常 - 没有错误。但是,当我单击该 UIWebView 页面中的链接时,我再次收到 didFailLoadWithError 错误。更有趣的是,我清除了错误消息,新页面仍然从我刚刚单击的链接加载,所以我知道连接良好。这是我的实现...
@synthesize webView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network Alert" message:@"No Internet Connection - Please Check Your Network Settings and Try Again" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: @"http://www.site.com/index.html"]]];
[webView addSubview:activity];
timer=[NSTimer scheduledTimerWithTimeInterval:(1.0/2.0)
target:self selector:@selector(loading) userInfo:nil repeats:YES];
}
- (void)loading {
if (!webView.loading)
[activity stopAnimating];
else
[activity startAnimating];
}