繁体   English   中英

如何在表格视图单元格中创建动态集合视图,而不快速重新加载表格视图?

[英]How to create dynamic collection view in a table view cell, without reloading table view swift?

我在 cellForRowAt 中使用此代码:

cell.frame = tableView.bounds
    cell.layoutIfNeeded()
    collectionView.reloadData()
    heightConstraint.constant = collectionView.collectionViewLayout.collectionViewContentSize.height

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableView.automaticDimension
}

这在第一次有效,但是当我将更多项目加载到集合视图时它不起作用,除非我使用tableView.reloadData()

但是当我使用tableView.reloadData()滚动停止一秒钟,我希望它流动而不会冻结。

有人有解决方案吗? 提前致谢。

每当您在显示单元格高度更改它时,您都需要告知表格视图。

您还没有展示如何或何时“将更多项目加载到集合视图” ......但在您这样做之后,请致电:

tableView.performBatchUpdates(nil, completion: nil)

这将导致表格视图重新计算和更新行高,而无需调用.reloadData()

您只能重新加载正在更新的单元格,以防您不想重新加载表格

    tableView.reloadRows(at: [IndexPath], with: .none)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM