how to reload a collectionview that is inside a ta

2019-04-15 01:57发布

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?

3条回答
神经病院院长
2楼-- · 2019-04-15 02:39

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()
查看更多
太酷不给撩
3楼-- · 2019-04-15 02:40

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

查看更多
该账号已被封号
4楼-- · 2019-04-15 02:45

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

查看更多
登录 后发表回答