Ios ***-[UITableView\u endCellAnimationsWithContext:]中的断言失败

Ios ***-[UITableView\u endCellAnimationsWithContext:]中的断言失败,ios,uitableview,restcomm,Ios,Uitableview,Restcomm,我正在开发一个iOS应用程序,有一个包含文本消息的UITableView(每条消息都有一个表格单元格)。当新消息到达时,将在UITableView中添加一个新单元格。起初,我使用单个UITableView部分,并在其下添加所有单元格 在我决定更改方案并使用多个部分,每个部分一行之前,所有这些都工作得很好(这是我发现的在单元格之间设置空格的最干净的方法)。此方案的问题是,每次尝试添加新单元格时,都会出现以下异常: 2015-09-30 11:48:35.659 restcomm messenger

我正在开发一个iOS应用程序,有一个包含文本消息的UITableView(每条消息都有一个表格单元格)。当新消息到达时,将在UITableView中添加一个新单元格。起初,我使用单个UITableView部分,并在其下添加所有单元格

在我决定更改方案并使用多个部分,每个部分一行之前,所有这些都工作得很好(这是我发现的在单元格之间设置空格的最干净的方法)。此方案的问题是,每次尝试添加新单元格时,都会出现以下异常:

2015-09-30 11:48:35.659 restcomm messenger[15069:489766]***-[UITableView\u endCellAnimationsWithContext:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit\u Sim/UIKit-3505.16/UITableView.m:1702中的断言失败

我在执行[self.tableView endUpdates]时得到它(完整代码见下文)

我在类似的问题中检查了很多答案,但我认为我做的一切都是对的。以下是“有趣”的代码部分:

新消息到达,更新备份存储并将行插入表:

...
// update the backing store
[self.messages addObject:[NSDictionary dictionaryWithObjectsAndKeys:type, @"type", msg, @"text", nil]];

[self.tableView beginUpdates];
// trigger the new table row creation
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:[self.messages count] - 1]]
                      withRowAnimation:animation];
[self.tableView endUpdates];
...
节和行计数回调:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [self.messages count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
填充单元格回调:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *type = [[self.messages objectAtIndex:indexPath.section] objectForKey:@"type"];
    if ([type isEqualToString:@"local"]) {
        LocalMessageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"local-message-reuse-identifier" forIndexPath:indexPath];
        cell.senderText.text = [[self.messages objectAtIndex:indexPath.section] objectForKey:@"text"];
        return cell;
    }
    else {
        RemoteMessageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"remote-message-reuse-identifier" forIndexPath:indexPath];
        cell.senderText.text = [[self.messages objectAtIndex:indexPath.section] objectForKey:@"text"];
        return cell;
    }
}
我希望这能奏效。请记住,对于原始方案(1个部分可能是行),它可以正常工作:(

如果您想了解更多详细信息,以下是相关表视图控制器的完整代码:

欢迎任何提示


Antonis

使用完整准确的错误消息更新您的问题。您省略了消息的导入部分。意思是“重要”而不是“导入”。@rmaddy根据请求添加了完整的错误消息。thanks@atsakiridis你有没有弄清楚是什么导致了这一断言?