I want to redraw the content of cells in CollectionView. And reload the collection.
dataSource for Collection is data
Doing this works:
@IBAction func change(_ sender: UISwitch) {
for iCell in 0..<data.count
let indexPath = IndexPath(row: iCell, section: 0)
if let aCell = myCollection.cellForItem(at: indexPath) as? MyCollectionViewCell {
aCell.someProperty = newValue
aCell.setNeedsDisplay()
}
}
myCollection.reloadData()
}
But, if I reload first, myCollection.cellForItem return nil, so nothing happens.
@IBAction func change(_ sender: UISwitch) {
myCollection.reloadData()
for iCell in 0..<data.count
let indexPath = IndexPath(row: iCell, section: 0)
if let aCell = myCollection.cellForItem(at: indexPath) as? MyCollectionViewCell {
aCell.someProperty = newValue
aCell.setNeedsDisplay()
}
}
}
Why ? Is it because myCollection.cellForItem is called before reload has completed ? Could not find hint in Apple's doc.