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 }
source share