There is no instance of UICollectionViewLayoutAttributes for layoutAttributesForSupplementaryElementOfKind: UICollectionElementKindSectionHeader

Sometimes, when I call this code when the UICollectionView is not ready (Instantly after calling collectionView.reloadData() ), it resets the application

  let sectionHeaderAttributes: UICollectionViewLayoutAttributes = self.collectionView.layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: indexPath)!; 

Application termination due to the uncaught exception "NSInternalInconsistencyException", reason: "no UICollectionViewLayoutAttributes instance for -layoutAttributesForSupplementaryElementOfKind: UICollectionElementKindSectionHeader on path {length = 2, path = 0 - 0} '

How to verify that a UICollectionView is β€œready” before I call the code? How do we protect to prevent a failure?

+5
source share

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


All Articles