Change view in all collection view cells

Viewed 194

I have a collection view where each cell has a video (played through AVPlayer) and a red circle. When a button in the view controller is clicked, the color of all cell's circles should be changed to blue, and then if clicked again, changes it back to red.

So what I need to be able to do is: when the button is clicked in the controller view, change the circle view in all cells, visible or not. The reason I say visible or not is because I only show one cell on the screen at a time. The user swipes to go to the next cell.

I have already tried using reloadData() to update all cell's circles when the button is clicked, however, the problem I discovered is that the video resets back to the beginning (and I need it not to do that, not just for the visible cell, but for all cells).

What are my other options?

1 Answers

When a button in the view controller is tapped you would need to change the data/collection/array of data that you are loading in your collection view. In order to achieve the result in (for example didSelectItemAtIndexPath:(NSIndexPath *)indexPath) you should change the data model for that specific cell/collection item. You can add for instance property isSelected for your collection view data model(s).

In your case, calling reload data calls all the UICollectionViewDelegate & UICollectionViewDataSourcemethods, however since you have not change the data using, the result/UI returns to the initial state.

Related