![](/img/trans.png)
[英]Swift: How to display a CollectionView inside a TableViewCell Programmatically
[英]how to reload a collectionview that is inside a tableviewcell
我在tableViewCell中有一个collectionView
例如: credit: 如何使用StoryBoard在UITableViewCell中快速构建一个collectionView
我想在更新信息时重新加载collectionView。
我在collectionView的cellForItemAtIndexPath中放置了一个print来测试它是否被调用但是它没有被调用。 如何让collectionView重新加载?
我发现了怎么样! 在我的tableViewCell类中,我只需要将collectionView链接为一个插座,所以在我的tableViewCell的cellForRowAtIndexPath
我只需要调用cell.collectionView.reloadData()
使用UITableView
indexPath.row
为集合视图创建标签,并使用标签创建UICollectionView
的实例并重新加载!
tableview单元格中的第1个创建此函数:
func collectionReloadData(){
DispatchQueue.main.async(execute: {
self.collectionView.reloadData()
})
}
然后从中调用它
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { ...
cell.collectionReloadData()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.