我有一个UICollectionView
. 我想添加一个标题。我的标题只会是一个UILabel
. 我有 :
1) 在 IB 中选择“Section Header”作为 Collection View 附件。
2)在 IB 中创建了一个 Collection Reusable View,在侧面,声明为collectionViewHeader
.
3)添加了这些行:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
if (kind == UICollectionElementKindSectionHeader) {
return collectionViewHeader;
}
return nil;
}
但他们永远不会被调用。
我是否必须为该标签创建一个类才能使用
[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
?
为什么它不像UITableView
你只需拖放任何你想要的标题那么简单?!事情太复杂了UICollectionView
……