【发布时间】:2013-04-02 05:04:26
【问题描述】:
我有一个UIWebView,想在它加载时显示一个活动指示器。然后在webViewDidFinishLoading 时隐藏它。唯一的问题是我得到了这个NSURLErrorDomain 错误-999 的事情。在四处搜索后,我发现this fix 可以不显示任何错误消息,但我的webViewDidFinishLoading 永远不会被调用来摆脱我的活动指示器和我正在进行的其他事情。我想我可以在我的 webViewDidFailWithError 方法中调用didFinishLoading 方法,如果它以-999 失败,但这似乎超级hacky 和错误。有关如何解决此问题的任何想法?
编辑*
我已经弄清楚了 webview 被要求加载两次的位置,所以我能够摆脱错误 -999。但是,除非我尝试加载 webview 两次(在这种情况下,webViewDidFinishLoading 方法只被调用一次),否则似乎没有调用任何委托方法。
- (void)viewDidLoad
{
self.webView.delegate = self;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(refresh)
name:@"DidBecomeActive"
object:nil];
[super viewDidLoad];
}
-(void)refresh{
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://myapp.com/app/"]]];
self.webView.scrollView.bounces = NO;
}
- (void)webViewDidFinishLoading:(UIWebView *)wv
{
NSLog(@"finished loading");
[self.activityInd stopAnimating];
[self.view bringSubviewToFront:wv];
}
- (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error
{
NSLog(@"Failed: %@", error);
if([error code] == NSURLErrorCancelled){
return;
}
[self.activityInd stopAnimating];
[[[UIAlertView alloc] initWithTitle:@"Can't find server" message:@"Check your internet connection and try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]show];
}
【问题讨论】: