How reload only one item from a cell in a collectionView? Swift 4

Viewed 5004

I have a collectionView with one cell and 3 items like this collectionView with 3 items enter image description here

I need to refresh only one item every second, in this case the "Label 2" needs to change every second, but when I make collectionView.reloadData() the UIImage and all the cell blinks a little and occasionally changes the image

2 Answers

Call reloadItems(at:) and pass in an array containing a single IndexPath of the cell you want to reload.

The Xcode docs on UICollectionView are quite good. You should read them.

var indexPaths = [IndexPath]()
collectionView.reloadItems(at: indexPaths)

Call this method to selectively reload only the specified items. This causes the collection view to discard any cells associated with those items and redisplay them.

Related