Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you are calling reloadData while the user is dragging the view, that might be the reason.</p> <p>I had crashes related to this with similar crash reports and "fixed" the issue by delaying the reloadData call until after the user has finished scrolling the view. E.g. create a wrapped method instead of calling reloadData directly.</p> <pre><code>- (void)updateData { if (self.collectionView.isTracking) { self.updateDataOnScrollingEnded = YES; } else { [self.collectionView reloadData]; } } </code></pre> <p>Then when scrolling ends, call the updateData method (if needed) from the scroll view's delegate methods.</p> <pre><code>- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { if (!decelerate) { [self scrollViewStopped:scrollView]; } } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { [self scrollViewStopped:scrollView]; } - (void)scrollViewStopped:(UIScrollView *)scrollView { if (self.updateDataOnScrollingEnded) { [self updateData]; self.updateDataOnScrollingEnded = NO; } } </code></pre> <p>My guess is that there is a weak reference to the highlighted cell's indexPath somewhere inside of the collectionView, and that calling reload will dealloc that indexPath. When the collectionView then tries to unhighlight the cell, it crashes.</p> <p>EDIT:</p> <p>As mentioned in comments below, this "solution" has some flaws. While investigating the issue further, it seems that in my case the problem had to do with multiple reloadData calls being queued on the main thread during the dragging of the collection view. When there was only one reloadData call, everything was fine, but whenever there was more than one – crash!</p> <p>Since I always had exactly one section in my collectionView i replaced the reloadData call with </p> <pre><code>reloadSections:[NSIndexSet indexSetWithIndex:0] </code></pre> <p>However, this causes the cells to quickly fade out and back in again which I avoided with the following method (it would probably be better off as a category on the collection view)</p> <pre><code>- (void)reloadCollectionView:(UICollectionView *)collectionView animated:(BOOL)animated { [UIView setAnimationsEnabled:animated]; [collectionView performBatchUpdates:^{ [collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]]; } completion:^(BOOL finished) { [UIView setAnimationsEnabled:YES]; }]; } </code></pre> <p>So far, this has worked well for me and it also allows for the data to actually be updated while scrolling.</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