1

I want to modify my UICollectionView Cells on selection and deselection. While backgroundView and selectedBackgroundView work automatically, this doesn't cover more complex cases of wanting to change text colour for example.

Prior to iOS 10 I could simply:

  1. configure cell depending on isSelected in cellForItemAt
  2. modify it to the selected state in didSelectItemAt
  3. modify it to the de-selected state in didDeselectItemAt

However, since iOS 10 changes to UICollectionView, there is a corner case where the cell can go off-screen, I can select an on-screen cell, then roll the previously-selected cell and see it in the selected configuration. I now have two selected cells visually, even though there is only one actually selected cell.

This is because while the cell was off-screen, I couldn't get hold of it in didDeselectItemAt to configure it. It remains un-updated until it is recycled.

I think I have found an answer and since I haven't seen it elsewhere, posting it below so it might be helpful. Would appreciate any other ideas to make sure I'm thinking the right way.

1 Answers1

0

This question is a re-phrased duplicate of UICollectionView cell selection and cell reuse

Check out my answer regarding iOS10 in particular below: https://stackoverflow.com/a/40749073/2039497

Community
  • 1
  • 1