THIS IS iOS 15 ONLY - THE SAME CODE WORKS FOR iOS 14.x USING XCODE 13.x, see below for details
When using background elements with UICollectionViewFlowLayout and UICollectionViewCompositionalLayout in iOS 15 the following happens on .reloadData()
, .reconfigureItems(...)
, and .reloadItems(...)
only (initial load is fine):
- collectionView:viewForSupplementaryElementOfKind:atIndexPath: is called for background view
- Background view is dequeued SUCCESSFULLY
- viewForSupplementaryElementOfKind returns the view
- App crashes post viewForSupplementaryElementOfKind (sometimes up to seconds later) saying viewForSupplementaryElementOfKind has returned null
I have verified:
- viewForSupplementaryElementOfKind IS dequeueing a cell
- The cell IS the correct element
- The element is returning
- viewForSupplementaryElementOfKind IS valid
- viewForSupplementaryElementOfKind loads correctly when the collectionView first loads; this only occurs on refreshing
PLEASE, re-read the very top statement again before replying to ensure you are not replying "you/viewForSupplementaryElementOfKind is returning nil, check you are not returning nil". I will happily run additional test.