Hi everyone,
In my collection view, I have implemented a "selection" feature that changes the background color of a cell on tap (without actually selecting the cell) by calling reloadItems(at:)
that cell's specific index path, and changing the background color in cellForItemAt
depending on whether that cell's index was tapped. Separately, I have an on-screen switch that toggles whether certain indicators are hidden in all cells, by calling reloadData()
and loading in a different appearance from cellForItemAt
depending on which option is selected.
Separately, these actions work as intended. However, if the cell is selected just before the switch is toggled, the indicators do not disappear, suggesting that the call to reloadItems(at:)
stopped or disrupted the call to reloadData()
. If I scroll to new cells, those cells appear with the indicators hidden correctly, and the original cells are set correctly when I scroll back (once the cells have been reloaded, they are correct). This malfunction does not happen in the reverse order, when the switch is toggled just before a cell is tapped.
I have put every function associated with the cell selection and indicator switch onto the main thread with DispatchQueue.main.async
, hoping that that would cause the calls to reloadItems(at:)
and reloadData()
to be forced to run in the order in which they were called, without overlapping. However, this did not work.
Why does the call to reloadItems(at:)
disrupt the call to reloadData()
, and is there a way to fix this problem? Is there a secret order of operations for reloading data in a collection view? Are there certain conditions that a call to reload must meet in order to fully reload that collection's cells?
Any help would be greatly appreciated.
Thank you,
Thomas