how to reload a collectionview that is inside a tableviewcell

前端 未结 4 1264
闹比i
闹比i 2020-12-19 10:25

I have a collectionView inside a tableViewCell

for example: \"example\" credit: How to use StoryBoard quick bui

相关标签:
4条回答
  • 2020-12-19 11:10

    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()
    
    0 讨论(0)
  • 2020-12-19 11:11

    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()
    }
    
    0 讨论(0)
  • 2020-12-19 11:13

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

    0 讨论(0)
  • 2020-12-19 11:17

    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()

    0 讨论(0)
提交回复
热议问题