我正在开发一个UICollectionView用来显示几张专辑的项目.项目显示正常,但现在我想在第一部分上方显示标题.
为此,我添加了registerNib:forSupplementaryViewOfKind:withReuseIdentifier:我的init方法.像这样:
[self.collectionView registerNib:[UINib nibWithNibName:@"AlbumHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kAlbumHeaderIdentifier];
(AlbumHeaderNib包含类的视图AlbumHeader,它是.的子类UICollectionView.)
之后,我实现了collectionView:viewForSupplementaryElementOfKind:atIndexPath方法:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    return [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kAlbumHeaderIdentifier forIndexPath:indexPath];
}
现在它应该尝试加载标题视图,我想.但事实并非如此,补充视图的方法不会被调用.
我错过了什么?坚持几个小时,已多次阅读文档UICollectionView,但似乎没有任何帮助.有什么想法吗?
我正在尝试添加标头UICollectionView.我使用了故事板并检查了Section Header.出现了一个新单元格,我正在尝试向其添加内容(带有一些文本的标签).问题是我可以在故事板中看到标签,但它不会出现在运行时.
为了确保标题显示,我将背景颜色更改为黄色,并且我能够在运行时看到黄色标题.仍然没有标签.
非常感谢帮助.