Note that there are some explanatory texts on larger screens.

plurals
  1. POCollectionView + UIKit Dynamics crashing on performBatchUpdates:
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COTry adding some code into the data delegate method that returns a cell and monitor the requests on the console. Likewise add logging to the methods return number of sections, number of cells. Perhaps the cv is requesting the latter before it even starts the batch update (in which case you need to move you beacon delete out of the block to before. Really, I sympathize - batch update was working just fine for me, I made a small change to my cells (added views), and wham, it started crashing all over and I had to make every change use reload :-(
      singulars
    2. COThanks David. Here is the output of the load, delete and crash sequence. Seems the counts are ok. [Link to output log](https://dl.dropboxusercontent.com/u/7373916/output.txt)
      singulars
    3. COCan you add logs before and after performBatchUpdates, and within the block before, middle, and after each code line. Also to make me happy add log the number of items in self.fetchedBeacons after the delete (make that the middle log message), then update log. I know this is a PITA, but what I did with CVs is write a really simple one view app that used labels in the cells, to play with the various modes of doing things. If that works and the complex code doesn't its CV screwing up (most likely). It seems CV changes behavior on how complex the cells are, which really makes it hard for us!
      singulars
 

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