ios - 在 UITableViewCell 内使用 UICollectionView 滚动滞后(闪烁)
问题描述
我已经实现了一个类似 UI 的 Appstore/Netflix,其中有一个 UITableView,并且在每个(自定义)单元格内都有一个水平滚动的 UICollectionView。
每个 UITableView 单元格都充当其 collectionView 的委托和数据源。数据由 tableView 单元格内的变量保存,该变量在 tableView 的 cellForRow 调用期间设置。
设置新变量后,didSet 执行一些操作并调用 collectionView.ReloadData() 以使 collectionView 反映当前数据。这会导致滚动时出现延迟,可能是因为每个 collectionView.ReloadData() 调用。
数据是一个结构,其中包含一些元数据和内容本身在一个数组中。
cellForRow:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: contentTableCellId, for: indexPath) as! ContentTableCell
cell.contentItem = contentItems[indexPath.row]
return cell
}
在 ContentTableCell 内部:
var contentItem: ContentItem!{
didSet{
... //some simple text label actions.
self.collectionView.reloadData()
}
}
解决方案
推荐阅读
- c - 用于生成 ftok() 密钥的公式是什么?
- c# - 将项目添加到 ObservableCollection 时出现 InteropServices.COMException
- pyspark - 带有数据框查询的 PySpark UDF 函数?
- python - 我正在尝试为 spacy 安装 en 但它给出了以下错误
- android - 在 Android Studio 中使用来自 SQLite 的数据填充 ExpandableListView
- javascript - 停止额外的间隔
- python - 如何处理 ML 分类中的字符串数据
- python-multiprocessing - python3中multiprocessing.Lock的共享字典
- javascript - setTimeout 在 iOS 中立即调用,同时启用模态视图,因此模态不会出现
- python - Tkinter Canvas.create_oval 不更新颜色