En-tête personnalisé dans UICollectionView avec Interface Builder sans storyboard

J'essaie d'append une vue personnalisée à la section d'en-tête de mon UICollectionView . J'ai le constructor d'interface de file xib mais je n'utilise pas de storyboard. J'ai vérifié l'en-tête de section dans Interface Builder mais n'apparaît pas UICollectionReusableView, que puis-je faire?

La solution la plus simple consiste à programmer (et conserver HeaderReusableView dans un autre file XIB):

 [self.collectionView registerNib:[UINib nibWithNibName:@"ItemHeaderView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kItemSectionHeaderViewID]; 

Alors:

 - (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { return CGSizeMake(60.0f, 30.0f);// width is ignored } 

Et bien sûr:

 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSSsortingng *)kind atIndexPath:(NSIndexPath *)indexPath { NSSsortingng *productId = nil; /// ItemHeaderView *view = nil; view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kItemSectionHeaderViewID forIndexPath:indexPath]; view.titleLabel.text = productId; view.backgroundColor = [UIColor yellowColor]; return view; }