首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionView &自定义UICollectionReusableView无效

UICollectionView &自定义UICollectionReusableView无效
EN

Stack Overflow用户
提问于 2013-05-16 05:41:21
回答 7查看 22.8K关注 0票数 11

我试图在我的UICollectionReusableView头中使用自定义UICollectionView (它有自己的类和XIB)。但是,在取了头部的数据之后,我什么也没有了。

我的脚步:

  1. viewDidLoad[self.collectionView寄存器类中注册类: forSupplementaryViewOfKind: UICollectionElementKindSectionHeader withReuseIdentifier:@“HeaderView”;
  2. 试图展示:

  • (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind:(NSIndexPath *)indexPath { UICollectionReusableView *reusableView = nil;if (bla == UICollectionElementKindSectionHeader) { CollectionViewHeader *收藏品HeaderView= self.collectionView ==UICollectionElementKindSectionHeader:@HeaderView“HeaderView”forIndexPath: indexPath;NSInteger节=indexPath区段;id NSInteger=区段;@“bla”;=;}返回;}}

有人能告诉我出了什么事吗?)谢谢你的建议

EN

回答 7

Stack Overflow用户

发布于 2013-05-16 06:00:34

我想你是在给xib添加标签。因此,您需要对头视图(而不是registerClass: )进行registerNib:

票数 14
EN

Stack Overflow用户

发布于 2013-10-24 16:12:22

  1. 在viewDidLoad部分注册您的报头nib/xib。 [self.collectionView registerNib: UINib nibWithNibName:@"headerCollectionViewCell“bundle:nil forCellWithReuseIdentifier:@”headerCell“;
  2. 创建自定义补充视图单元格。

  • (headerCollectionViewCell *)collectionView:(UICollectionView *)collectionViews viewForSupplementaryElementOfKind:(NSString *)kind:(NSIndexPath *)indexPath { UICollectionReusableView *reusableView = nil;if (Kin== UICollectionElementKindSectionHeader) { UINib *nib = UINib nibWithNibName:@" headerCollectionViewCell“bundle:nil;collectionViews registerNib:nib forCellWithReuseIdentifier:@@”headerCell“;collectionViews *收藏品headerCell= forIndexPath:indexPath;= @"What";=;}返回reusableView;}
票数 10
EN

Stack Overflow用户

发布于 2016-01-29 15:43:56

以防万一有人需要解决。您不必使用

代码语言:javascript
复制
[self.collectionView registerClass:...]

只需使用布局的委托方法返回标头类。

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

https://stackoverflow.com/questions/16579740

复制
相关文章

相似问题

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