我正在做一个项目,该项目使用一个UICollectionView
来显示几张专辑。这些项目显示得很好,但现在我想在第一部分上方显示一个标题。
为此,我在registerNib:forSupplementaryViewOfKind:withReuseIdentifier:
我的 init 方法中添加了 。像这样:
[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];
}
现在它应该尝试加载标题视图,我想。但事实并非如此,补充视图的方法不会被调用。
我错过了什么?卡住了几个小时,已经多次阅读UICollectionView
s 上的文档,但似乎没有任何帮助。有什么想法吗?