[英]how to reload a collectionview that is inside a tableviewcell
I have a collectionView inside a tableViewCell 我在tableViewCell中有一个collectionView
for example: 例如: credit: How to use StoryBoard quick build a collectionView inside UITableViewCell credit: 如何使用StoryBoard在UITableViewCell中快速构建一个collectionView
I would like to reload the collectionView when I update information. 我想在更新信息时重新加载collectionView。
I have put a print in the collectionView's cellForItemAtIndexPath to test if it is being called but it isn't. 我在collectionView的cellForItemAtIndexPath中放置了一个print来测试它是否被调用但是它没有被调用。 How can I get the collectionView to reload? 如何让collectionView重新加载?
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()
在我的tableViewCell类中,我只需要将collectionView链接为一个插座,所以在我的tableViewCell的cellForRowAtIndexPath
我只需要调用cell.collectionView.reloadData()
使用UITableView
indexPath.row
为集合视图创建标签,并使用标签创建UICollectionView
的实例并重新加载!
1st on tableview cell create this function: tableview单元格中的第1个创建此函数:
func collectionReloadData(){
DispatchQueue.main.async(execute: {
self.collectionView.reloadData()
})
}
then call it from 然后从中调用它
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { ...
cell.collectionReloadData()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.