有时我的应用程序运行良好,但有时会因以下错误而失败:
* WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame: delegate: * -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]
我在 WebKit 中发现了一些关于异常的其他问题,但没有发现 NSRangeException
。
我的代码:
- (id) init {
myWebView = [[UIWebView alloc] init];
myWebView.delegate = self;
[myWebView stopLoading];
return self;
}
- (void)loadUrl:(NSString *)urlAddress {
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView stopLoading];
[myWebView loadRequest:requestObj];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
if (!myWebView.isLoading) {
[myWebView stopLoading];
if (selectedInfo == LOADTable) {
NSString *html = [NSString stringWithFormat:@"%@",[myWebView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"]];
[myWebView stopLoading];
[self parseTable:html];
}
}
}
有没有人知道如何解决这个错误。
UIWebView
不显示在任何 UIView
上。仅用于加载 HTML。
最佳答案
能否请您发布parseTable:
方法的代码。此外,在调用 parseTable:
方法之前,请确保对 html 字符串进行 nil 检查。在 parseTable:
方法中,请确保在调用 objectAtIndex:
方法之前对 NSArray 计数进行安全检查。看起来您正在尝试从仅包含 6 个项目(最大索引 5)的 NSArray 访问第 7 个项目(索引 6)。
关于iOS 8 UIWebview 委托(delegate) : WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32548615/