gpt4 book ai didi

iphone - 标题 View 不是工作类注册错误,UICollectionView

转载 作者:行者123 更新时间:2023-12-01 16:50:16 25 4
gpt4 key购买 nike

我试图在 UICollectionView 上显示标题,但类未注册。下面是我的代码。

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = nil;

if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
identifier = @"header";
}

UICollectionReusableView *supplementaryView = [self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];

return supplementaryView;
}

// Registering class in viewDidLoad

[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];

有一件事要告诉我没有创建任何其他类或 View Controller ,只是注册 UICollectionReusableView,就像我注册 UICollectionView 类一样,它可以工作,不知道为什么每次都会给出相同的错误。
我只是想显示我放在单元格上的图像,所以没有进行子分类。只是做了
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];

同样尝试了标题。
我每次得到的错误是:
UICollectionElementKindSectionHeader with identifier Test Header View - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

请指导我没有得到什么是错误,已经花了两天时间。我错过了什么没有得到。请指导。

最佳答案

看起来您正在寻找 UICollectionElementKindSection**Footer**但您注册为 UICollectionElementKindSection**Header**

关于iphone - 标题 View 不是工作类注册错误,UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16676381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com