UITableView上的iOS Swift ReloadData不会刷新UITableViewCell内的UICollectionView

Din*_*ašo 9 uitableview ios uicollectionview swift

我有一个UITableView Controller类,里面是一个String数组.Table视图有1个单元格原型,其中包含一个带有1个单元原型的UICollectionView.

通过将数组传递到tableview单元格来填充CollectionView,该单元格是UICollectionView Delegate和DataSource.

当我对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
    }
Run Code Online (Sandbox Code Playgroud)

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
    }
Run Code Online (Sandbox Code Playgroud)

Gag*_*iOS 5

请尝试调用reloadDataUICollectionView对阵列的每个更新.如果你只使用一个单元格中UITableView,那么你可以重新加载cellForRowAtIndexPath的方法,UITableView否则你可以可以在调用后调用reloadDataUITableView.