最近在處理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
