我正在使用UICollectionView
来显示多个相册的项目。项目显示正常,但现在我想在第一部分上方显示标题。UICollectionView标题未显示
为此,我将registerNib:forSupplementaryViewOfKind:withReuseIdentifier:
添加到了我的init方法中。像这样:
[self.collectionView registerNib:[UINib nibWithNibName:@"AlbumHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kAlbumHeaderIdentifier];
(该AlbumHeader
笔尖包含类AlbumHeader
,这是UICollectionView
一个子类的视图)
之后,我实现collectionView:viewForSupplementaryElementOfKind:atIndexPath
方法:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
return [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kAlbumHeaderIdentifier forIndexPath:indexPath];
}
现在它应该尝试加载标题视图,我想。但它不会,补充视图的方法不会被调用。
我错过了什么?卡住了几个小时,多次阅读了关于UICollectionView
的文档,但似乎没有任何帮助。有什么想法吗?
对于任何人仍然遇到这个问题,为了让我做这个工作,我还必须给'collectionview.footerReferenceSize'的大小。不知道该请求是否是iOS 7特有的... –
这是一个难以置信的提示。非常感谢,Guido! – Fattie
享受赏金! :) – Fattie