I have one table view in which every cell contains one collection view!
1) display only two cell in collectionview as my issue is when we scroll the tableview, collectoinview cell content is repeated in many other cell of tableview
myCode:
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
here I get only fixed width of collectionview without setting width according to content size & collectionview cells are repeated in other cell of tableview, even if cell is one , it will show 2 cell(when scrolled)
when load for the first time
when tableview is scrolled
//for storing array in collectionview from tableview
func fillCollectionView(with array: [String]) {
self.collectionArr = array
self.collectionView.reloadData()
}
I don't know what fillCollectionView
does but it looks like you didn't consider that the table view cells are reused. So every time you call fillCollectionView
you have to reset the content of your cell or the content or your collection view.
reload collectionView inside tableview
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()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.