首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionReusableView未显示

UICollectionReusableView未显示
EN

Stack Overflow用户
提问于 2017-07-20 23:09:37
回答 1查看 686关注 0票数 2

我已经将<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>添加到我的集合视图中并设置了我的UICollectionView,如下所示。

代码语言:javascript
复制
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerReuseIdentifier];

我还添加了必要的方法。

代码语言:javascript
复制
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return CGSizeMake(self.view.frame.size.width, 44.0f);
}

- (UICollectionReusableView *)supplementaryViewForElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"supplementaryViewForElementKind called");
    if ([elementKind isEqualToString:UICollectionElementKindSectionHeader]) {
        UICollectionReusableView *header = [self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                                                                               withReuseIdentifier:headerReuseIdentifier
                                                                                      forIndexPath:indexPath];
        header.backgroundColor = [UIColor redColor];
        return header;
    }

    return nil;
}

然而,supplementaryViewForElementKind从未被调用过。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2017-12-13 02:24:16

如果您已经在接口生成器中添加了头视图,并且已经分配了类,那么您应该在代码中删除registerClass调用。那么它应该会显示出来。在你的委托方法中放一个断点,看看它是被调用的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45218690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档