私は奇妙なクラッシュに悩まされており、一日中それを修正しようとしています. 基本的にセルに重力と衝突の振る舞いを追加するカスタム UICollectionViewLayout があります。
実装はうまくいきます![self.collectionView performBatchUpdates:] を使用して 1 つのセルを削除しようとすると、問題が発生します。
次のエラーが表示されます。
2013-12-12 21:15:35.269 APPNAME[97890:70b] *** Assertion failure in -[UICollectionViewData validateLayoutInRect:], /SourceCache/UIKit_Sim/UIKit-2935.58/UICollectionViewData.m:357
2013-12-12 20:55:49.739 APPNAME[97438:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView recieved layout attributes for a cell with an index path that does not exist: <NSIndexPath: 0x975d290> {length = 2, path = 0 - 4}'
私のモデルは正しく処理されており、モデルからアイテムが削除されていることがわかります!
削除するアイテムの indexPaths は、オブジェクト間で正しく渡されています。collectionView の更新がクラッシュしないのは、最後のセルを削除したときだけです。そうしないと、クラッシュが発生します。
セルを削除するために使用しているコードは次のとおりです。
- (void)removeItemAtIndexPath:(NSIndexPath *)itemToRemove completion:(void (^)(void))completion
{
UICollectionViewLayoutAttributes *attributes = [self.dynamicAnimator layoutAttributesForCellAtIndexPath:itemToRemove];
[self.gravityBehaviour removeItem:attributes];
[self.itemBehaviour removeItem:attributes];
[self.collisionBehaviour removeItem:attributes];
[self.collectionView performBatchUpdates:^{
[self.fetchedBeacons removeObjectAtIndex:itemToRemove.row];
[self.collectionView deleteItemsAtIndexPaths:@[itemToRemove]];
} completion:nil];
}
セル属性を処理する CollectionView デリゲートは、以下の基本的なものです。
- (CGSize)collectionViewContentSize
{
return self.collectionView.bounds.size;
}
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
return [self.dynamicAnimator itemsInRect:rect];
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
return [self.dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath];
}
私がすでに試したことは成功していません: - レイアウトの無効化 - データのリロード - UIDynamicAnimator から動作を削除し、更新後に再度追加します
洞察はありますか?
問題のあるソース コードは、このリポジトリで入手できます。チェックアウトしてください。コード リポジトリ
一番。ジョージ。