首页 > 技术文章 > failed to obtain a cell from its dataSource 问题处理

widgetbox 2018-12-28 15:18 原文

最近在处理bugly问题的时候,总会看到回话列表有奔溃,但是由于没有啥具体的细节原因也无从下手。

只知道ConversationListViewController这个类的奔溃,报的问题是这个,也只有这个信息,所以只能tableview下手

#17009 NSInternalInconsistencyException

UITableView (<UITableView: 0x10e1ad400; frame = (0 88; 414 327); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x280df53e0>; layer = <CALayer: 0x2807a1040>; contentOffset: {0, 156.33333333333334}; contentSize: {414, 394}; adjustedContentInset: {0, 0, 0, 0}>) failed to obtain a cell from its dataSource (<CustomChatUIViewController: 0x10e1b0000>)

YuLin + 10902176

 网上查找半天,UITableView常见Crash主要有下面几类:

  • dataSource更新后没同步刷新UITableView
  • UITableView dataSource is not set
  • Invalid update
  • failed to obtain a cell from its dataSource

最后发现代码中有一处为了避免数组越界加了这个判断,返回了nil,会导致failed to obtain a cell from its dataSource

 if (_conversationList.count<=indexPath.row) {
       
            return nil;
            
  }


//修改后

 if (_conversationList.count<=indexPath.row) {//datasource不同步,会出现越界问题,返回nil,有failed to obtain a cell from its dataSource问题
             static NSString *ident = @"tempcell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ident];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ident];
            }
            cell.hidden = YES;
            return cell;
            
        }

 

//看之后的版本效果了,ConversationListViewController的奔溃率下降,那就是这个问题了
 
byzqk

 

推荐阅读