gpt4 book ai didi

ios - 下载来自 url 的数据时,重新加载位于 uitableviewcell 内的 Collection View

转载 作者:行者123 更新时间:2023-11-28 08:42:55 29 4
gpt4 key购买 nike

所以我在 TableView 单元格中有一个 Collection View ,没有从 url 下载 TableView 类数据,可以说图像已下载,然后我需要在这些 Collection View 单元格上显示这些图像,所以我正在做的是正在重新加载 TableView ,但 Collection View 没有重新加载,我需要用下载的数据重新加载它们

最佳答案

确实非常简单(假设您的 viewController、customTableViewCell 和 customCollectionViewCell 正常工作),只要您需要在表格 View 单元格内重新加载 collectionViews,就可以在 Controller 中使用这段代码来声明您的表格 View :

//在你的 ViewController 中

var myRow = 0 // set the index path row of your tableview cell
var mySection = 0 // and the index path section

DispatchQueue.main.async(execute: {
if let index = IndexPath(row: myRow, section: mySection) as? IndexPath {
if let cell = self.MyTableView.dequeueReusableCell(withIdentifier: "cell", for: index) as? MyCustomTableViewCell {
cell.collectionReloadData()
}
}
})

现在在您的 TableViewCell 中

class MyCustomTableViewCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {

@IBOutlet weak var collectionView: UICollectionView!
func collectionReloadData(){
DispatchQueue.main.async(execute: {
self.collectionView.reloadData()
})
}

//Dont forget to set delegates
override func awakeFromNib() {
super.awakeFromNib()
self.collectionView.delegate = self
self.collectionView.dataSource = self
}
}

这里是此代码的一个示例,第 3 节“Cartas Recomendadas”中的 Collection View 已重新加载:

enter image description here

关于ios - 下载来自 url 的数据时,重新加载位于 uitableviewcell 内的 Collection View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35982053/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com