【发布时间】:2016-08-08 16:01:45
【问题描述】:
我正在尝试创建一个与 iOS 相同但只有四年的日历视图。
The hierarchy is like:
UICollectionView: One Section for each year
UICollectionViewCell: 12 cells/items for 12 months in an year
UICollectionView:
UICollectionViewCell: Upto 31 cells for month day string, which have UILabel as their content.
附上截图。
为了克服延迟滚动,我删除了 Month 单元格的数据源。容器视图控制器本身就是两个集合视图的数据源。
12 个月的集合视图已被子类化以存储年份值的索引路径。从本教程中得到了这个技巧:https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell/
但问题仍然存在,因为我在显示月份单元格之前调用了 reloadData。
为了解决这个问题,我确实重写了 UICollectionViewCell 的 prepareForReuse() 方法,并在 monthCollectionViewCell 中将 indexPath、delegate 和 datasource 属性设置为 nil。此外,删除了 reloadData 调用。但滚动仍然滞后。
教程链接与我的工作流程几乎相同。
【问题讨论】:
-
我会认真考虑不要让每个月都有自己的
UICollectionView。您嵌套了太多视图。取而代之的是一个包含 12 个单元格的UICollectionView,并构建一个自定义的UIView子类来绘制文本本身并进行自己的命中测试。 -
我应该改用多个 CATExtLayers 吗?
-
我会覆盖
drawRect:并使用NSStringdrawing methods。
标签: ios uicollectionview lazy-loading uicollectionviewcell uicollectionreusableview