IOS Swift ReloadData in UITableView does not update UICollectionView inside UITableViewCell

I have a UITableView Controller class, and inside it is a String array. In the table view, there is 1 prototype cell, and in it there is a UICollectionView with 1 prototype cell.

The CollectionView is populated by passing the array to the tableview cell, which is a delegate of the UICollectionView and DataSource.

When I make changes to the array inside the TableViewController and call self.tableView.reloadData (), the CollectionView inside the cell is NOT updated.

How to fix it?

thanks

EDIT:

Code in 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 } 

Code in 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 } 
+9
source share
2 answers

Try calling reloadData from the UICollectionView for each update in the array. If you use only one cell in a UITableView , you can reload the cellForRowAtIndexPath UITableView method, which you can call after calling reloadData in the UITableView .

+5
source

You can easily reload the nested UICollectionView : fooobar.com/questions/11493221 / ...

0
source

All Articles