iosswiftuitableviewuikit

In current UIKit is there a way to access the array of all current cells in the recycler pool?


I've just looked at the headers of UITableView and can't see anything; in olden days there was an array something like "_reusableCells" but it seems to be gone.

I guess one could keep a list of them as they are made but (a) not performant (b) a bit messy/impossible to watch them be released etc.

Is there a way?

I suppose having them all sign up for a notification is one approach, but it seems a bit fraught.


Found it! (The old version.)

https://stackoverflow.com/a/6164346/294884

This seems to no longer exists in UIKit - does anyone know how to find it today?


Solution

  • WTT @DonMag it seems to be this simple,

    let spares = mainTable.value(forKey: "_reusableTableCells")
    print(spares, "\n\n")
    

    It seems this gives the list of reusable cells not currently in use, ie literally the "offscreen" ones, rather than giving you "all assembled cells, in use or on standby".

    Thus if you need to (say) flag "all cells" in some way, you'd add together that set and all showing ones.