长话短说,我只是在这么做:
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没有问题,但这并不理想。
如果我分几次调用它,它就会崩溃。如果只有一次,那么没有任何问题。
我是不是漏掉了什么?我以为数字是匹配的?这里的问题是什么?
发布于 2015-03-25 01:07:11
你能确认你真的在insertItemsAtIndexPaths:调用中崩溃了吗?假设是,错误代码明确地告诉您,当您在集合视图上调用insertItemsAtIndexPaths:时,该节中的项数没有变化。你能发布你的集合视图数据源方法(例如collectionView:numberOfItemsInSection:),这样我们就可以确认你是否正确地处理了它?
另外,你能确认这一切都发生在主线程上吗?如果是这样,这里会发生以下两件事之一: 1)在此代码被攻击之前,您正在其他地方修改您的数据源。2)在命中此代码之前,您正在执行其他集合视图更新(插入/移除)。
https://stackoverflow.com/questions/29203456
复制相似问题