Error could not dequeue a view of kind UICollectionElementKindCell

前端 未结 13 1227
耶瑟儿~
耶瑟儿~ 2020-12-16 09:34

Taking first plunge with collection views and am running into this error:

Terminating app due to uncaught exception \'NSInternalInconsistencyException

相关标签:
13条回答
  • 2020-12-16 10:23

    Swift 5

    1) Make sure you have a correct deque for HEADER, you might be using the regular for normal cells.

    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
            let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerId, for: indexPath)
            return header
        }
    

    2) doubleCheck the registration (ViewDidLoad)

    collectionView.register(HeaderCell.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerId)
    
    0 讨论(0)
提交回复
热议问题