未调用UICollectionReusableView方法 [英] UICollectionReusableView method not being called

查看:1878
本文介绍了未调用UICollectionReusableView方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 UICollectionView 中的部分有一个带图像的标题。

I want my sections in the UICollectionView to have a header with an image.

我已经按照这些步骤:


  • 在故事板上,为我的 UICollectionView 分配了一个标题作为附件

  • 给它一个标识符

  • 为它创建了 UICollectionReusableView 的子类

  • 将自定义类分配给故事板上的类。

  • 在标题附件中放置 ImageView / li>
  • .h 的自定义类中为 ImageView 设置了一个出口文件

  • viewDidLoad 实施以下内容:

  • at the storyboard, assigned a header as an accessory for my UICollectionView
  • gave it an identifier
  • created a subclass of UICollectionReusableView for it
  • assigned the custom class to the class at the storyboard.
  • put an ImageView at the header accessory
  • made an outlet for the ImageView at the custom class in the .h file
  • Implemented the following at viewDidLoad:

 

[self.collectionView registerClass:[ScheduleHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIdentifier];

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusableview = nil;

    if (kind == UICollectionElementKindSectionHeader)
    {
        ScheduleHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIdentifier forIndexPath:indexPath];

        headerView.headerImageView.image = [UIImage imageNamed:@"blah.png"];

        reusableview = headerView;
    }

    return reusableview;
}

我知道数据源和委托方法正在运行,因为我可以看到所有的细胞及其部分。但是,我没有我的标题。我在上面的方法中设置了一个断点,它永远不会被调用。

I know that the datasource and delegate methods are working because I can see all the cells and its sections. However, I don't have my headers. I put in a breakpoint at the method above and it's never being called.

我做错了什么?

推荐答案

看来你必须给你的标题一个非零大小或 collectionView:viewForSupplementaryElementOfKind:atIndexPath 不被调用。因此,要么设置流布局的 headerReferenceSize 属性,请执行以下操作:

It seems that you have to give your header a non-zero size or collectionView:viewForSupplementaryElementOfKind:atIndexPath isn't called. So either set the headerReferenceSize property of the flow layout like so:

flowLayout.headerReferenceSize = CGSizeMake(self.collectionView.frame.size.width, 100.f);

或者,实现 collectionView:layout:referenceSizeForHeaderInSection 如果你想按部分改变大小。

or, implement collectionView:layout:referenceSizeForHeaderInSection if you want to vary the size by section.

这篇关于未调用UICollectionReusableView方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆