Note that there are some explanatory texts on larger screens.

plurals
  1. POCollectionView + UIKit Dynamics crashing on performBatchUpdates:
    text
    copied!<p>I'm stucked with a strange crash and trying to fix it all day long. I have a custom UICollectionViewLayout that basically adds gravity and collision behavious to the cells.</p> <p>The implementation works great! The problem happens when I try to delete one cell using: [self.collectionView performBatchUpdates:].</p> <p>It gives me the following error:</p> <pre><code>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: &lt;NSIndexPath: 0x975d290&gt; {length = 2, path = 0 - 4}' </code></pre> <p><strong>My model is being handled correctly and I can see it removing the item from it!</strong></p> <p>The indexPaths of the item to delete is being passed correctly between objects. The only time the collectionView update doen't crash is when I delete the last cell on it, otherwise, the crash happens.</p> <p>Here's the code I'm using to delete the cell.</p> <pre><code>- (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]; } </code></pre> <p>The CollectionView delegates that handles the cell attibutes are the basic ones below.</p> <pre><code>- (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]; } </code></pre> <p>Things I already tried with no success: - Invalidating the layout - Reloading the data - Removing the behaviours from the UIDynamicAnimator and adding them again after the update</p> <p>Any insights?</p> <p>A source code with the problem is available on this repository. Please check it out. <a href="https://github.com/ghvillasboas/CollectionViewDynamics" rel="noreferrer">Code Repository</a></p> <p>Best. George.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload