J'essaie de créer des en-têtes pour ma collectionView with dynamic height. Mais quand je mets en œuvre « referenceSizeForHeaderInSection », les application se bloque à l'exception suivante:La méthode CollectionView 'referenceSizeForHeaderInSection' génère une exception
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindSectionHeader with identifier FeedHeader - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
est Ci-dessous le code de l'en-tête CollectionView:
func numberOfSections(in collectionView: UICollectionView) -> Int {
return feedArray.count
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSize(width: collectionView.frame.size.width - 20 , height: 70)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsetsMake(10, 10, 10, 10);
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "FeedHeader", for: indexPath) as! FeedHeader
return header
}
classe FeedHeader est vide comme je l'ai pas ajouté étiquettes à l'en-tête encore:
class FeedHeader: UICollectionReusableView
{
}
Lorsque je supprime la mise en œuvre de referenceSizeForHeaderInSection, l'application fonctionne sans aucun problème.
Vous avez également lié l'en-tête à la classe dans le storyboard. Quel pourrait être le problème?
Merci d'avance.
L'application fonctionne correctement lorsque je supprime l'implémentation referenceSizeForHeaderInSection. Je ne suis pas le problème avec l'enregistrement de l'en-tête. – Vyshakh
avez-vous essayé le code supérieur? @Vyshakh –
Pour plus de précisions lire ce https://stackoverflow.com/a/29656061/8432814 répondre –