我一直在尝试在非故事板iPad项目中继承UICollectionReusableView.我已经在IB中构建了一个视图并将其连接到我的自定义类,在我的集合视图所在的viewController中注册该类以供重用,并且正在调用它
UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
但是,UICollectionView中的标题区域中没有显示任何内容.我认为我需要使用编码器初始化视图,但我不确定如何正确地执行此操作.我按照我发现的几个例子,但标题视图仍然没有出现在我的集合视图中.
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
[[NSBundle mainBundle] loadNibNamed:@"CVHeaderView" owner:self options:nil];
[self addSubview:self.categoryNameLabel];
}
return self;
Run Code Online (Sandbox Code Playgroud)
}
谁能指出我正确的方向?
如果您使用故事板并选择页眉/页脚initWithCoder:将选中复选标记.
如果您不使用故事板(或不单击页眉/页脚)但手动initWithFrame:将其挂起,则必须注册您的自定义类并将被调用.
[self.collectionView registerClass:[GameCardCell class] forCellWithReuseIdentifier:@"GameCardCell"];
[self.collectionView registerClass:[PlayerHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"PlayerHeaderView"];
[self.collectionView registerClass:[PlayerFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"PlayerFooterView"];
Run Code Online (Sandbox Code Playgroud)
注意:两者都只会被调用一次.如果视图出来缓存prepareForReuse将被调用.
| 归档时间: |
|
| 查看次数: |
5116 次 |
| 最近记录: |