Search code examples
iosswiftuitableviewuicollectionviewuicollectionviewcell

Is it possible to access all cells not equal to the indexpath when using didSelectItemAtIndexPath?


I am new to Swift and new to coding, so please forgive me if my question is vague, or the answer is obvious.

I have a collectionView and a number of cells inside. When I select a cell, I want to change the color of every cell except the selected one. I'm using the delegate method: didSelectItemAtIndexPath. How might I be able to access the cells at indexpath not equal to the indexpath of the selected cell?


Solution

  • One way to do this is, you can store your indexPath in a variable in class and reload your collection view in didSelectItemAtIndexPath after storing this indexPath. After that in your cellForItemAtIndexPath, check for this indexPath stored and change the color of cell.