I have a UITableView Controller class, and inside of it is a String array. The Table view has 1 cell prototype and in it a UICollectionView with 1 cell prototype.
The CollectionView is populated by passing the array into the tableview cell, which is a UICollectionView Delegate and DataSource.
When I make changes to the array inside the TableViewController, and call self.tableView.reloadData(), the CollectionView inside the cell does NOT update.
How do I fix this?
Thank you
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
}
Please try to call reloadData
of UICollectionView
on every update in array.
If you are using only one cell in UITableView
then you can reload in cellForRowAtIndexPath
method of UITableView
else you can can call after calling of reloadData
of UITableView
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With