我想将当前基于 TableView 的数据网格转换为新的 UICollectionView
类。
这就是我当前的网格的样子:
我的网格有两个标题:
- 年份(2006a、2007a 等)和
- 类型(“收入”、“EBITDA”等)。
从 Apple 的文档中,我了解到我需要子类化 FlowLayout 来获取两个 header ( Apple Documentation ),特别是重写 layoutAttributesForSupplementaryViewOfKind:atIndexPath:
以支持新的补充 View (标题)。
但是,我没有找到任何有关如何执行此操作的示例或教程。由于我被困在这里,如果您能为我指出正确编码的正确方向,我将不胜感激。
Cảm ơn.
我发布了一个示例 đây如何支持装饰 View 。补充 View 的情况类似,但有以下区别:
- 您可以在 UICollectionView 实例上调用
– registerClass:forSupplementaryViewOfKind:withReuseIdentifier:
,而不是在布局上注册 NIB 或类
- 在 UICollectionView 的 View Controller 中,您将实现类似于普通单元格方法的
-collectionView:viewForSupplementaryElementOfKind:atIndexPath:
- 在布局子类中,您需要实现以下方法
-layoutAttributesForSupplementaryViewOfKind:atIndexPath:
以将补充 View 定位在其位置
- hiện hữu
–layoutAttributesForElementsInRect:
中,确保添加您想要的所有补充 View (类似于我发布的示例中的装饰 View )
我现在无法访问我的示例代码,但我稍后会发布。
Tôi là một lập trình viên xuất sắc, rất giỏi!