複数のボタンを備えた標準のView Controllerを備えたアプリがあります。各ボタンは、固有の UIWebView を持つ個別のビュー コントローラーにリンクします。各 UIWebView には didFailLoadWithError が実装されており、正常に動作しているようです。Wi-Fi をオフにして、メイン ビュー コントローラー ページから 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];
}