- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString* CellIdentifier = @"MessageCellIdentifier";
MessageTableViewCell* cell = (MessageTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[MessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
Message* message = [self.dataModel.messages objectAtIndex:indexPath.row];
[cell setMessage:message];
return cell;
}
我正在开发一个聊天应用程序,我在同时发送和接收消息时遇到异常。以下是异常消息
断言失败 - [UITableView _endCellAnimationsWithContext:],/ SourceCache / UIKit / UIKit-2380.17 / UITableView.m:1070 2013-04-30 16:55:14.314 [2689:907] 由于未捕获的异常而终止应用 'NSInternalInconsistencyException',原因:'无效更新:无效 第0节中的行数 *。
更新后的现有部分中包含的行数(19)必须等于更新前该部分中包含的行数(17),加上或减去从该部分插入或删除的行数(1个已插入,0个已删除)并加上或减去移入或移出该部分的行数(0移入,0移出)。'
- (int)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.dataModel.messages count];
}
- (void)didSaveMsg:(NSMutableArray *)array1
{
self.dataModel.messages = array1;
[tableview insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:array1.count-1 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[self scrollToNewestMessage];
}
- (void)scrollToNewestMessage
{
dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), ^(void){
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:(self.dataModel.messages.count - 1) inSection:0];
[tableview scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
});
[tableview reloadData];
[[DBModel database]updateMessageCount1:mobileNo cnt:@"0"];
}
答案 0 :(得分:0)
错误消息是相当自我解释的 - 您告诉表视图要插入单个单元格,但是在表格的数据源中说它有两个额外的单元格要显示(19而不是17)。
问题几乎肯定不在您发布的代码中,它可能位于数据源的numberOfRows
方法中,也可能位于插入额外单元格的代码中。< / p>