我将集合视图作为表格视图的行。集合视图仅支持水平滚动。当我滚动到第一行中集合视图的末尾,然后滚动到表视图的底部时。当我还没有触及时,最后一个集合视图也位于结束位置。
我知道问题是因为桌面视图的
dequeueReusableCell
。我尝试过在 prepareForReuse()
中使用 UITableViewCell
。
我希望表视图的任何其他行都应该不受表视图其余行上完成的交互的影响。
您可以使用表视图的委托方法来存储(和恢复)集合视图的内容偏移量:
var xOffsets: [IndexPath: CGFloat] = [:]
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
xOffsets[indexPath] = (cell as? TableViewCell)?.collectionView.contentOffset.x
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
(cell as? TableViewCell)?.collectionView.contentOffset.x = xOffsets[indexPath] ?? 0
}
我尝试遵循相同的方法,但对我不起作用。