繁体   English   中英

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

[英]multiple collectionView cells inside tableView cells changing design on scroll

我有一个包含3个单元格的tableview collectionView 2在tableview中具有相同的设计单元格

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

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

滚动类别单元格更改设计到产品,对于产品相同,则需要类别单元格设计

这导致对UIViewReportBrokenSuperviewChain的Break进行调试。 在带有标签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
        }
}

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

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

在集合视图刷新期间更改布局可能会产生您遇到的意外错误。

暂无
暂无

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

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