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:
- configure cell depending on isSelected in
cellForItemAt
- modify it to the selected state in
didSelectItemAt
- 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.