0

I have a UITableView, which cells are UICollectionViews(a horizontal slider). Each UITableViewCell contains vary number of items. For example, the first row of the UITableView contains 3 pictures, the second row contains 2 pictures, and the third row contains 1 pictures, and so on. My data source looks like this

 `[
   [item1, item2, item3],
   [item1,item2], 
   [item1]
   [item1, item2, item3],
   [item1,item2], 
   [item1]
 ]`

after scrolling back and forth, it may looks like this

`[
   [item1, item2, item3],
   [item1,item2], 
   [item1,item2]
   [item1, item2],
   [item1,item2], 
   [item1]
 ]`

I researched and found out that I may need to override the prepareForReuse method in my custom class which subclass UITableViewCell as suggested here

ios uitableview uitableviewcell reuse has old data

In my custom UITableViewCell, I have a UICollectionView as my property. I wonder how should I reset the entire UICollectionView, or am I heading to the right direction?

Community
  • 1
  • 1
Kesong Xie
  • 1,316
  • 3
  • 15
  • 35

1 Answers1

0

It turns out that I can use collectionView.reloadData inside prepareForReuse method, and the cell in the tableView will remain updated

Kesong Xie
  • 1,316
  • 3
  • 15
  • 35