2017-03-27 74 views
1

我想创建一个简单的自定义布局UICollectionView以编程方式使用(即没有界面生成器)。UICollectionView自定义布局。补充意见不显示或查询

我根据文档做的一切:

  1. 子类UICollectionViewLayout并准备我的布局
  2. 覆盖layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath)并返回相应的布局属性
  3. 添加collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath)实现,我回到我的补充视图

我的问题是,既没有collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath)也没有layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath)正在调用,所以我看不到我的补充意见。

我已经仔细检查了我的实现都布局和补充视图创建,但我仍然无法得到它的工作。

回答

3

显然,这是不够的,有layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?其返回的补充意见的属性。

人们还需要返回补充意见的属性在layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?

我的错误是,我是为细胞在layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?

只返回布局属性一旦我添加布局属性的补充意见纳入返回的值通过layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?我有我的数据源方法调用和补充意见返回。

编辑:这个答案涵盖了iOS10 SDK。我还没有尝试过早期版本

+0

可以发布完整的代码吗? –

+0

layoutAttributesForItem()?不是RECT? –