ios6 - 子类化 UICollectionReusableView

标签 ios6

我一直在尝试在 Non-Storyboard iPad 项目中子类化 UICollectionReusableView。我在 IB 中构建了一个 View 并将其连接到我的自定义类,在我的 Collection View 所在的 viewController 中注册了该类以供重用,并在

中正确调用了它
UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

但是,在 UICollectionView 的标题区域中没有显示任何内容。我想我也需要用编码器初始化 View ,但我不确定如何正确地做到这一点。我遵循了几个我发现的例子,但标题 View 仍然没有出现在我的 Collection View 中。

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

谁能指出我正确的方向?

最佳答案

如果您使用 Storyboard并选择页眉/页脚复选标记 initWithCoder: 将被调用。

如果您不使用 Storyboard(或不单击页眉/页脚)而是手动连接它,您必须注册您的自定义类,然后 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"];

注意:两者都只会被调用一次。如果 View 从缓存中出来,将调用 prepareForReuse

关于ios6 - 子类化 UICollectionReusableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12810742/

相关文章:

objective-c - UIWebView 向下滚动输入焦点仅限 iOS 6

ios6 - 使用 UICollectionView 创建书架

controller - iPad 上 UIDocumentInteractionController : presentPreviewAnimated is not pushed into the navigation stack 的可能错误

ios - 根据照片方向设置自动旋转和首选方向

objective-c - 为什么 NSIndexPath 的 row 属性是有符号整数?

ios - 前后摄像头切换由加速度计决定

iphone - UIActionSheet 高度在 3.5 英寸设备上为 4 英寸

ios - 动态单元格大小

ios - 没有为 MKMapView w/ARC 释放内存

iphone - 不完整的实现 xcode buttons to disable buttons