我正在做一个项目,用UICollectionView
来展示几张专辑.这些项目显示得很好,但现在我想在第一部分上方显示一个标题.
为此,我在init方法中添加了registerNib:forSupplementaryViewOfKind:withReuseIdentifier:
.这样地:
[self.collectionView registerNib:[UINib nibWithNibName:@"AlbumHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kAlbumHeaderIdentifier];
(AlbumHeader
Nib包含类AlbumHeader
的视图,它是UICollectionView
的子类.)
之后,我实施了collectionView:viewForSupplementaryElementOfKind:atIndexPath
种方法:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
return [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kAlbumHeaderIdentifier forIndexPath:indexPath];
}
现在,我想它应该try 加载header视图.但事实并非如此,辅助视图的方法不会被调用.
我错过了什么?被困了几个小时,我已经多次阅读了UICollectionView
年代的文档,但似乎没有任何帮助.有什么 idea 吗?