【问题标题】:NSInternalInconsistency Exception in UITableViewUITableView 中的 NSInternalInconsistency 异常
【发布时间】:2013-05-15 09:49:56
【问题描述】:
- (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"];


}

【问题讨论】:

  • 一次显示你的 numberOfRows 方法??
  • 例外是删除或添加行。只需检查您的 numberOfRows 方法吗?一旦粘贴。
  • 添加行
  • 只需将您的 numberOfRows 方法粘贴到您的问题中
  • 你能粘贴你的代码如何添加行吗?

标签: objective-c


【解决方案1】:

错误消息是不言自明的——你告诉表格视图你想插入一个单元格,但是在表格的数据源中说它有两个额外的单元格要显示(19 个而不是 17 个)。

几乎可以肯定,问题不在您发布的代码中,而在您的数据源的numberOfRows 方法中,或者在您插入额外单元格处的代码中。

【讨论】:

  • 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 动画:YES]; });
  • 这是我更新 tableView 的地方
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-12
相关资源
最近更新 更多