6

I have a collectionView inside a tableViewCell

for example: example credit: How to use StoryBoard quick build a collectionView inside UITableViewCell

I would like to reload the collectionView when I update information.

I have put a print in the collectionView's cellForItemAtIndexPath to test if it is being called but it isn't. How can I get the collectionView to reload?

Community
  • 1
  • 1
stephw
  • 513
  • 1
  • 4
  • 19
  • I'm voting to close this question as off-topic because its not really an issue as "i just needed to call cell.collectionView.reloadData()" – some_id Feb 25 '16 at 09:05

4 Answers4

10

I found out how! In my tableViewCell class I just need to link the collectionView as an outlet so in my tableViewCell's cellForRowAtIndexPath I just needed to call cell.collectionView.reloadData()

DeyaEldeen
  • 10,847
  • 10
  • 42
  • 75
stephw
  • 513
  • 1
  • 4
  • 19
6

Simplest Way

for cell in tableView.visibleCells {
    (cell as? YourTableViewCell)?.collectionView.reloadData()
}

Or If you need to reload Specific UICollectionView

if let cell = tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? YourTableViewCell {
   cell.collectionView.reloadData()
}
ZAFAR007
  • 3,049
  • 1
  • 34
  • 45
1

1st on tableview cell create this function:

func collectionReloadData(){
        DispatchQueue.main.async(execute: {
            self.collectionView.reloadData()
        })
    }

then call it from

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

    cell.collectionReloadData()
Nuno Ferro
  • 1,261
  • 12
  • 17
0

create tags for collection view with indexPath.row of UITableView and create an instance of the UICollectionView using the tag and reload !

DeyaEldeen
  • 10,847
  • 10
  • 42
  • 75
good4pc
  • 711
  • 4
  • 17