CollectionView重新加载功能无法在TableViewCell内部运行

时间:2019-04-09 16:29:09

标签: swift uitableview uicollectionview

我在tableviewcell内部创建了一个collectionview。我将数据传递给tableviewcell的类。我试图调用collectionview重载函数,但是该函数永远不会运行。

关于单元格课程:

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
}

0 个答案:

没有答案
相关问题