UICollectionViewFlowLayout with self-tuning cells crashing after reloadData

I have a custom UICollectionViewFlowLayout with non-zero estimatedItemSize for cells. I add and delete cells inside the View collection, reloading the data, and sometimes I get a failure when trying to scroll to the cell that has just been deleted / added.

Using the backtrace tool, I get the following result:

frame # 9: 0x0000000185c8385c CoreFoundation - [__ NSArrayM objectAtIndex:] + 264 frame # 10: 0x000000018aeabb18 UIKit - [_ UIFlowLayoutSection setSize: forItemAtIndexPath:] + 708, frame # 11: 0x000000018ae7cc5c UIKit- [UICollectionViewFlowLayout invalidationContextForPreferredLayoutAttributes: withOriginalAttributes:] + 156 frame # 12: 0x000000018ae646c4 UIKit- [UICollectionView _checkForPreferredAttributesInView: originalAttributes:] + 212 frame # 13: 0x000000018a844968 UIKit- [UICollectionView _createPreparedCellForItemAtIndexPathttutes: 7outayoutoututayoutoututayoututa

I have an assumption that my stream layout may cache cells.

UPDATE: My problem appears in iOS 8.3, but not in previous versions, including 8.2.

+6
source share
1 answer

Do not use the cell for self-calibration with a non-zero value of estimatedItemSize . It is a trap.

Introduce the UICollectionViewDelegateFlowLayout collectionView(collectionView:collectionViewLayout:indexPath:) , where you calculate the cell size by calling systemLayoutSizeFittingSize on the user cell instance.

You can find more information in this question: UICollectionView - dynamic cell height?

0
source

Source: https://habr.com/ru/post/985516/


All Articles