Created
February 19, 2018 20:30
-
-
Save radianttap/c06445d8cd24ed636a4f12fe5370a0c5 to your computer and use it in GitHub Desktop.
Why the hell this crashes in UICollectionView?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let expandedSections = [0, 3, 8] | |
let indexSet = IndexSet(expandedSections) | |
collectionView?.performBatchUpdates( | |
{ | |
[unowned self] in | |
if isInserted { | |
self.collectionView?.insertItems(at: indexPaths) | |
} else { | |
self.collectionView?.deleteItems(at: indexPaths) | |
} | |
if !indexSet.isEmpty { | |
self.collectionView?.reloadSections(indexSet) | |
} | |
}, completion: { | |
_ in | |
} |
2 years later, I have the answer. Happens when you do this:
let indexPath = IndexPath(item: NSNotFound, section: section)
let attr = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, with: indexPath)
and somewhere along the way you do collectionView.reloadSections()
Problem is indexPath, which should be:
let indexPath = IndexPath(item: 0, section: section)
Hi I'm facing the same issue using framework for CollectionView well that is weird.
Thanks for posting the reason why it happens.
Although i did not understand fully why this is happening.
My only hint is that somehow indexSet is over-floating.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crash is this:
Where did it find NSNotFound..?!