iOS 8 UIWebview 委托(delegate) : WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame:

标签 ios objective-c webview uiwebview webkit

有时我的应用程序运行良好,但有时会因以下错误而失败:

* 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/

相关文章:

ios - 如何延迟 Swift 中发生的事情?

ios - 签名 "WebDriverAgentRunner"需要一个开发团队。在项目编辑器中选择一个开发团队

objective-c - 替换字符串不起作用

iphone - 无法弄清楚为什么我的应用程序在使用 NSKeyedArchivers/NSKeyedUnarchivers 时崩溃

ios - 如何避免在 iOS 中使用 Unity MovePlayerOnYAxis 时出现延迟?

ios - 带参数的 Swift 传递闭包

ios - 根据 iDevice 磁强计读数旋转 UIView

android - 如何使用 android Webview 显示 res 中原始文件夹中的 HTML 页面?

webview - 我如何在 Xamarin Forms WebView(iOS) 中使用 WKWebView 而不是 UIWebView

android - 如何计算无需滚动即可适合 WebView 的文本