ios – UICollectionView Header xib没有显示

ios – UICollectionView Header xib没有显示,第1张

概述我有一个collectionview,我想使用xib作为标题.但是,xib不会出现.首先,我尝试在xib中添加标签,但没有出现.然后我将整个背景颜色设置为红色.它没有出现. collectionview项目为标题留下了空白,但它完全是空白的.类似的SO线程是 this和 this,但由于我没有使用故事板而我的标题高度大于零,因此它们无法解决我的问题.这是我的所有相关代码: #import "Sco @H_502_0@ @H_502_0@ 我有一个collectionvIEw,我想使用xib作为标题.但是,xib不会出现.首先,我尝试在xib中添加标签,但没有出现.然后我将整个背景颜色设置为红色.它没有出现. collectionvIEw项目为标题留下了空白,但它完全是空白的.类似的SO线程是 this和 this,但由于我没有使用故事板而我的标题高度大于零,因此它们无法解决我的问题.这是我的所有相关代码:

#import "scoreboardCollectionVIEwController.h"#import "scoreboardCollectionVIEwCell.h"#import "scoreboardReusableVIEw.h"#import "scoreboardModel.h"#import "scoreboard.h"...- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    // Register cell classes    UINib *cellNib = [UINib nibWithNibname:@"scoreboardCollectionVIEwCell" bundle:nil];    [self.collectionVIEw registerNib:cellNib forCellWithReuseIDentifIEr:@"cell"];    [self.collectionVIEw registerClass:[scoreboardReusableVIEw class] forSupplementaryVIEwOfKind:UICollectionElementKindSectionheader withReuseIDentifIEr:@"scoreboardheader"];    self.collectionVIEw.backgroundcolor = [UIcolor colorWithPatternImage:[UIImage imagenamed:@"dark_fish_skin_"]]; }...- (CGSize)collectionVIEw:(UICollectionVIEw *)collectionVIEw layout:(UICollectionVIEwLayout*)collectionVIEwLayout referenceSizeforheaderInSection:(NSInteger)section{    return CGSizeMake(self.vIEw.frame.size.wIDth,34);}- (UICollectionReusableVIEw *)collectionVIEw:(UICollectionVIEw *)collectionVIEw           vIEwForSupplementaryElementOfKind:(Nsstring *)kind                                 atIndexPath:(NSIndexPath *)indexPath {    scoreboardReusableVIEw *vIEw = [[scoreboardReusableVIEw alloc] init];    vIEw = [collectionVIEw dequeueReusableSupplementaryVIEwOfKind:UICollectionElementKindSectionheader                                              withReuseIDentifIEr:@"scoreboardheader"                                                     forIndexPath:indexPath];    return vIEw;}

这是我的xib的屏幕截图:

解决方法 好的,我解决了.问题在于我的vIEwDIDLoad方法

[self.collectionVIEw registerClass:[scoreboardReusableVIEw class] forSupplementaryVIEwOfKind:UICollectionElementKindSectionheader withReuseIDentifIEr:@"scoreboardheader"];

从我使用笔尖开始,应该是:

[self.collectionVIEw registerNib:[UINib nibWithNibname:@"scoreboardReusableVIEw" bundle:nil]          forSupplementaryVIEwOfKind:UICollectionElementKindSectionheader                 withReuseIDentifIEr:@"scoreboardheader"];
@H_502_0@ 总结

以上是内存溢出为你收集整理的ios – UICollectionView Header xib没有显示全部内容,希望文章能够帮你解决ios – UICollectionView Header xib没有显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1008042.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存