【发布时间】:2016-07-13 06:50:38
【问题描述】:
我正在尝试将 indexPath 存储在 NSMutableArray 中
[checkBoxIndexArray addObject:[NSIndexPath indexPathForRow:indexPath.row inSection:?]];
- (void)reloadItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
{
cell.checkBox.image = [UIImage imageNamed:@"check"];
[self.collectionView insertItemsAtIndexPaths:checkBoxIndexArray];
}
但我不知道我应该为 inSection 赋予什么价值。我尝试输入 0,1 但仍然无法正常工作。我收到以下错误
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (2) must be equal to the number of items contained in that section before the update (2), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).
以下代码出现此错误
[self.collectionView insertItemsAtIndexPaths:checkBoxIndexArray];
请告诉我应该为 inSection 设置什么值。
【问题讨论】:
-
您是否尝试将 section 设置为 indexPath.section ?另外,如果您已经有了需要保存的 indexPath,为什么不直接将您拥有的 indexPath 对象添加到数组中,而不是创建副本。
-
我尝试设置 indexPath.section 但我仍然遇到同样的错误
-
从您得到的错误来看,您似乎正在动态插入或删除单元格。您能否详细解释一下您何时何地收到此错误并显示 tableView 数据源的代码。
-
请输入您尝试过的全部代码。你在哪里添加这个
indexPathobject -
确保 checkBoxIndexArray 的数组计数和您从 numberOfItemAtIndexPath 数据源返回的数组应该相同。您收到此错误是因为计数不同。
标签: ios uicollectionview nsmutablearray nsindexpath