【问题标题】:tableview refresh crush Thread1:signal SIGABRTtableview 刷新粉碎 Thread1:signal SIGABRT
【发布时间】:2016-08-24 08:16:34
【问题描述】:

我的应用程序是一个IM应用程序,当应用程序进入后台并再次回到前台时会崩溃。 这是我的部分代码。

-(void)uiAddChatroomMessages:(NSArray*)messages{
    NSMutableArray *indexPaths = [[NSMutableArray alloc]init];
    int i = (short)self.messageArray.count ;
    for (RTIMMessage *msg in messages) {
        [self.messageArray addObject:msg];
    }
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
    [indexPaths addObject:indexPath];
    [self.chatMessageTableView beginUpdates];
    [self.chatMessageTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
    [self.chatMessageTableView endUpdates];
    [self.chatMessageTableView reloadData];
}

运行到这段代码“[self.chatMessageTableView endUpdates]”,它会崩溃并提示“Thread1:signal SIGABRT”。

2016-08-24 15:49:18.500 RTIM_iOS_Demo[1834:1326398] * 断言 -[UITableView _endCellAnimationsWithContext:] 中的失败, /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.12/UITableView.m:1716 2016-08-24 15:49:18.590 RTIM_iOS_Demo[1834:1326398] * 终止 应用程序由于未捕获的异常“NSInternalInconsistencyException”, 原因:'无效更新:第 0 节中的行数无效。 更新后现有部分中包含的行数 (62) 必须等于该节之前包含的行数 更新(57),加上或减去插入或删除的行数 从该部分(插入 1 个,删除 0 个)并加上或减去数字 移入或移出该部分的行数(0 移入,0 移出)。 *** 第一次抛出调用堆栈:(0x18238adb0 0x1819eff80 0x18238ac80 0x182d10154 0x1876e1808 0x100072ccc 0x1000728b0 0x100095244 0x10009468c 0x100077d20 0x100241a7c 0x100241a3c 0x1002474e4 0x182340d50 0x18233ebb8 0x182268c50 0x183b50088 0x187552088 0x1000a5340 0x181e068b8) libc++abi.dylib: 以未捕获的方式终止 NSException 类型的异常

【问题讨论】:

  • 从不insertRowsAtIndexPaths之后立即调用reloadData。 insert 方法会自动重新排列表格视图。

标签: ios objective-c uitableview


【解决方案1】:

在您的方法中,您向self.messageArray 添加了一些新对象,但只添加了一行。修改你的代码。

-(void)uiAddChatroomMessages:(NSArray*)messages{
    NSMutableArray *indexPaths = [NSMutableArray array];
    NSUInteger i = self.messageArray.count;
    for (RTIMMessage *msg in messages) {
        [self.messageArray addObject:msg];
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        [indexPaths addObject:indexPath];
        i ++;
    }

    [self.chatMessageTableView beginUpdates];
    [self.chatMessageTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
    [self.chatMessageTableView endUpdates];
    [self.chatMessageTableView reloadData];
}

【讨论】:

    【解决方案2】:

    根据堆栈跟踪,您的索引路径似乎是错误的。您正在使用数组计数作为行索引,尝试使用 (array count-1),希望它会起作用。

    【讨论】:

      【解决方案3】:

      插入您后,numberOfRowsInSection 返回的数字必须与新的预期值匹配。您可能会返回一个常量或数组中未更改的多个元素。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-30
        • 1970-01-01
        • 1970-01-01
        • 2017-11-20
        • 2018-12-16
        • 1970-01-01
        • 2011-07-20
        • 1970-01-01
        相关资源
        最近更新 更多