簡體   English   中英

UITableView 上的 iOS Swift ReloadData 不會刷新 UITableViewCell 內的 UICollectionView

[英]iOS Swift ReloadData on UITableView does not refresh UICollectionView inside of UITableViewCell

我有一個 UITableView Controller 類,里面是一個 String 數組。 Table 視圖有 1 個單元格原型,其中有一個 UICollectionView 和 1 個單元格原型。

CollectionView 通過將數組傳遞到 tableview 單元格來填充,這是一個 UICollectionView 委托和數據源。

當我對 TableViewController 內的數組進行更改並調用 self.tableView.reloadData() 時,單元格內的 CollectionView 不會更新。

我該如何解決?

謝謝

編輯:

TableViewController 中的代碼:

@IBAction func addToArrayAction(sender: AnyObject) {
        self.testArray.append("Ant-Man")
        self.tableView.reloadData()
    }

    var testArray = ["Guardinas", "Iron Man", "Avengers", "Captain America"]

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("collectionContainerCell", forIndexPath: indexPath) as! TableViewCell
        cell.testArray = self.testArray
        return cell
    }

UITableViewCell 中的代碼:

var testArray: [String]?

    override func awakeFromNib() {
        super.awakeFromNib()

        self.collectionView.delegate = self
        self.collectionView.dataSource = self

    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("collectionViewCell", forIndexPath: indexPath) as! CollectionViewCell

        cell.movieTitleLabel.text = self.testArray![indexPath.item]
        cell.movieYearLabel.text = "2016"

        return cell
    }

請嘗試在數組中的每次更新時調用UICollectionView reloadData 如果您使用的是只有一個格UITableView那么您可以在重裝cellForRowAtIndexPath方法UITableView其他你能可以在調用后調用reloadDataUITableView

添加 cell.collectionView.reloadData() 后,我的項目中的 CollectionView 滾動速度非常慢。 這樣的問題怎么解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM