【问题标题】:When I called [tableView insertRowsAtIndexPaths: withRowAnimation:], crashed in iOS10当我调用 [tableView insertRowsAtIndexPaths: withRowAnimation:] 时,在 iOS10 中崩溃了
【发布时间】:2016-10-17 08:16:58
【问题描述】:
- (void)registerCellCallBack:(id<CellCallBack>)callBack {
    int i = 0;
    for(; i < _dataSource.count; ++i) {
        id<CellCallBack> oldCallBack = _dataSource[i];
        if([callBack key] <= [oldCallBack key]) {
            break;
        }
    }
    if(i < _dataSource.count) {
        [_dataSource insertObject:callBack atIndex:i];
    } else {
        [_dataSource addObject:callBack];
    }

    [self.table beginUpdates];
    [self.table insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    [self.table endUpdates]; //--crashed here called "NSInternalInconsistencyException(SIGABRT)"
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}

在 iOS9 中运行良好的代码,在 iOS10 中崩溃了,但在我调试代码时没有出现。

崩溃信息:

无效更新:第 0 节中的行数无效。 更新后现有部分中包含的行数 (7) 必须等于该节之前包含的行数 更新(0),加上或减去插入或删除的行数 从该部分(插入 1 个,删除 0 个)并加上或减去数字 移入或移出该部分的行数(0 移入,0 移出)。

【问题讨论】:

  • 只删除开始更新和结束更新。就是这样。

标签: ios uitableview


【解决方案1】:

您需要按以下方式进行更改:

 [self.table reloadData];

来自

 [self.table beginUpdates];
 [self.table insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
 [self.table endUpdates]; //--crashed here called "NSInternalInconsistencyException(SIGABRT)"

【讨论】:

  • 是的,我已经替换了,但是效率不高。我只想知道ios10做了什么改动。
  • 所以这不是 ios 10 的错误。
  • 确保以后不要在调用插入行之前调用 reload。否则会导致插入前和插入后行不匹配的错误提示。
  • 和?当您用 reloadData 替换时,您会破坏表格的动画
  • 我已经根据问题给出了答案,而不是动画。并且没有提到动画。
猜你喜欢
  • 2017-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多