swift - Collectionview 重新加载功能不在 tableviewcell 内运行
问题描述
我在 tableviewcell 中创建了一个 collectionview。我将数据传递给 tableviewcell 的类。我试图调用 collectionview reload 函数,但该函数永远不会运行。
关于单元格:
TableViewCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource
@IBOutlet weak var statCollection: UICollectionView!
var collectionArray = [] // This creates the collection cells
//DELEGATE SELF (datasource, delegate) at awakeFromNib()
func loadItems(){
print("load2")
self.statelem = self.selectedStatparent?.statelements.sorted(byKeyPath: "statname", ascending: true)
print("Elem: \(self.statelem?.count)") //=4
DispatchQueue.main.async(execute: {
self.statCollection.reloadData()
})
}
创建单元格,并调用函数(在 ViewController 上):
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = statTableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! StatTableViewCell
cell.statcategoryName.text = statkategoria?[indexPath.row].Categoryname
cell.selectedStatparent = statkategoria?[indexPath.row]
DispatchQueue.main.async(execute: {
cell.loadItems()
})
return cell
}
解决方案
推荐阅读
- python - Pandas 将两列合并到另一个 Dataframe 列
- angular - 可重复使用的 Angular 11 模板
- spring-boot - Spring 配置服务器无法从 codecommit 获取属性
- matlab - 在matlab中舍入特定列
- node.js - Certbot 独立用于 localhost 安装问题
- bitbucket - 使用 react build 的 bitbucket-pipeline.yml 部署 SFTP
- verilog - 16 位 ALU 总是导致 0
- java - 迭代 JSON 字段及其 subjson 字段并将键值与其他类的 java 对象进行比较
- python-3.x - 在python中的同一个excel表中写入多个数据框,一个在另一个之下
- django - Django 的验证级别