Ios6 子类化UICollectionReusableView

Ios6 子类化UICollectionReusableView,ios6,Ios6,我一直在尝试在一个非故事板iPad项目中对UICollectionReusableView进行子类化。我已经在IB中构建了一个视图,并将其连接到我的自定义类,在集合视图所在的viewController中注册了该类以供重用,并且在中正确调用了它 UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind

我一直在尝试在一个非故事板iPad项目中对UICollectionReusableView进行子类化。我已经在IB中构建了一个视图,并将其连接到我的自定义类,在集合视图所在的viewController中注册了该类以供重用,并且在中正确调用了它

UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
但是,UICollectionView中的“我的标题”区域中没有显示任何内容。我想我需要太多的编码器视图,但我不知道如何正确地做到这一点。我遵循了我发现的几个示例,但标题视图仍然没有出现在我的集合视图中

- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
    [[NSBundle mainBundle] loadNibNamed:@"CVHeaderView" owner:self options:nil];
    [self addSubview:self.categoryNameLabel];
}
return self;
}


有人能给我指出正确的方向吗?

在我的例子中,当第一次将其出列时,会自动调用
initWithFrame:
。尝试实现此方法并查看其是否有效。

如果使用故事板并选择页眉/页脚复选标记,则将调用
initWithCoder:

[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"];
如果不使用故事板(或不单击页眉/页脚),而是手动连接,则必须注册自定义类,并将调用
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"];
注意:这两个函数只调用一次。如果视图从缓存中出来,将调用
prepareforeuse

[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"];