UICollectionView断言失败 - [UICollectionView _endItemAnimations]

时间:2015-03-23 04:50:07

标签: ios objective-c uicollectionview

长话短说,我只是这样做:

NSIndexPath *indexPath = [NSIndexPath indexPathForItem:insPoint inSection:0];
[self.m_orders insertObject:orderRecord atIndex:insPoint];
[self.m_collectionView insertItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];


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).

如果我将其更改为reloadData没有问题,但这并不理想。

如果我在几次连续中调用它会崩溃。如果它只有一次,则不存在任何问题。

我在这里遗漏了什么吗?我认为数字匹配?这会是什么问题?

1 个答案:

答案 0 :(得分:0)

你能确认你在insertItemsAtIndexPaths:电话上真的崩溃了吗?假设是,错误代码特别告诉您,当您在集合视图上调用insertItemsAtIndexPaths:时,该部分中的项目数未发生变化。您可以发布您的集合视图数据源方法(例如collectionView:numberOfItemsInSection:),以便我们确认您正确处理它吗?

另外,你能否证实这一切都发生在主线程上?如果是这样,这里发生了两件事之一: 1)在此代码被命中之前,您正在其他地方修改数据源。 2)在执行此代码之前,您正在执行其他集合视图更新(插入/删除)。