gpt4 book ai didi

ios - tableView 单元格内的多个 collectionView 单元格在滚动时更改设计

转载 作者:行者123 更新时间:2023-11-28 13:37:28 24 4
gpt4 key购买 nike

我有一个包含 3 个单元格的 tableview,它们是 collectionView 2 具有相同的设计表格 View 中的单元格就像

1-类别单元格(collectionView垂直)

2&3- 产品单元格(collectionView 水平)

滚动类别单元格将设计更改为产品,对于采用类别单元格设计的产品也是如此

这导致 Break on UIViewReportBrokenSuperviewChain 进行调试。在带有标签 4 的 collectionView 上

我尝试了 collectionView.collectionViewLayout.invalidateLayout() 但事情变得更糟了

tableView(cellForrowAt)(
if indexPath.row == 3{
let cell = self.homeTableView.dequeueReusableCell(withIdentifier: "TableCollectionViewCell") as! TableCollectionViewCell
cell.collectionView.delegate = self
cell.collectionView.dataSource = self
cell.collectionView.tag = 4
cell.collectionView.isScrollEnabled = false
return cell
}
}


collectionView(cellForItemAt){

if collectionView.tag == 4 {
let nib = UINib(nibName: "ProductCell", bundle: nil)
collectionView.register(nib, forCellWithReuseIdentifier: "ProductCell")
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProductCell", for: indexPath) as! ProductCell
cell.setup(product: self.newProducts[indexPath.row])
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 20, left: 0, bottom: 10, right: 0)
layout.minimumInteritemSpacing = 10
layout.minimumLineSpacing = 10
collectionView.collectionViewLayout = layout
return cell
}
}

最佳答案

您不应该在每次检索单元格时都向 collectionView 注册您的 Nib。您应该在实例化/配置 collectionView 时注册您计划使用的所有单元格类型,或者至少检查该单元格是否已经注册。

同样,您不应该在用于检索单元格的代码中更改 Collection View 的布局。在大多数情况下,布局将设置一次。在某些复杂的情况下,您可能希望在调度 reloadData() 之前更改它以响应正在下载的新数据或某些用户交互(从横向更改为纵向等)。

在 Collection View 刷新期间更改布局可能会产生您遇到的意外错误。

关于ios - tableView 单元格内的多个 collectionView 单元格在滚动时更改设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56435853/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com