gpt4 book ai didi

ios - UITableView 中的 CollectionView 单元格重复

转载 作者:行者123 更新时间:2023-11-28 15:15:41 25 4
gpt4 key购买 nike

我有一个 TableView ,其中每个单元格都包含一个 Collection View !

1) 在 collectionview 中只显示两个单元格,因为我的问题是当我们滚动 tableview 时,collectoinview 单元格内容在 tableview 的许多其他单元格中重复

我的代码:

let tags = Tblarr[indexPath.row]["hashtags"] as! [String]
if tags.count != 0
{
for var i in 0 ... tags.count - 1
{
if i < 2
{
cell.tagsView.addTag(tags[i])
cell.collectionView.isHidden = false
}
}
if tags.count > 2
{
cell.lblCount.isHidden = false
cell.lblCount.text = "+\(tags.count - 2)"
}
else
{
cell.lblCount.isHidden = true
}
}
else{
cell.lblCount.isHidden = true
cell.collectionView.isHidden = true
}
cell.fillCollectionView(with: cell.tagsView.tags)
cell.widthConstraint.constant = cell.collectionView.contentSize.width

这里我只得到collectionview的固定宽度,没有根据内容大小设置宽度&collectionview单元格在tableview的其他单元格中重复,即使单元格是一个,它也会显示2个单元格(滚动时)

第一次加载时

when load for the first time

滚动tableview时

when tableview is scrolled

//用于从tableview中存储数组到collectionview中

func fillCollectionView(with array: [String]) {
self.collectionArr = array
self.collectionView.reloadData()
}

最佳答案

在 tableview 中重新加载 collectionView

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
cell.fillCollectionView.reloadData()
}

func fillCollectionView(with array: [String]) {
self.collectionArr.removeAll
self.collectionArr = array
self.collectionView.reloadData()

关于ios - UITableView 中的 CollectionView 单元格重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46906006/

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