【发布时间】:2012-10-03 00:40:46
【问题描述】:
我正在开展一个项目,该项目使用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];
}
我想现在它应该尝试加载标题视图。但它没有,补充视图的方法没有被调用。
我错过了什么?坚持了几个小时,多次阅读UICollectionViews 上的文档,但似乎没有任何帮助。有什么想法吗?
【问题讨论】:
标签: objective-c cocoa-touch uicollectionview