如何将标头设置为UICollectionView

时间:2016-02-26 06:01:50

标签: ios objective-c uicollectionview uicollectionreusableview

我想将默认的标题标题设置为UICollectionView。我使用下面的代码,它崩溃了。

-viewDidLoad

[feedcollectionview registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"cell"];

-viewForSupplementaryElementOfKind

UICollectionReusableView *reusableview = nil;
  if (kind == UICollectionElementKindSectionHeader) {
        UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
        [headerView setBackgroundColor:[UIColor redColor]];        
        reusableview=headerView;

谢谢

1 个答案:

答案 0 :(得分:0)

ViewDidLoad中的

标识符与viewForSupplementaryElementOfKind不同 你必须选择@" cell"或@" HeaderView"