Deploy a system similar to how UITableView deactivates cells already created.

I need to implement a grid to display some view objects on an iPad. To get the most out of the SDK, I thought I would use a UITableView to keep track of my rows, and then inject some kind of counter to return the correct columns to place in my cells.

The enumerator works fine. I just pass the tableViews viewController to a one-dimensional array, and the enumerator splits it into a “pseudo-two-dimensional set”, however I would like to make the grid approach similar to UITableViews for both rows and columns:

[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

As now, I create the number of column views needed for each row, and add them manually to the cell in cellForRowAtIndexPath:

I would like to make a method called:

 columnsForRowAtIndexPath: 

and let it work like cellForRowAtIndexPath..

So the question is, how does tableView avoid initializing my cells over and over again and how can I implement this behavior?

-

I can't figure out if the tableView will copy cells or create new ones using NSCoding to return cells with minimal overhead. Guessing NSMatrix would be really nice to have in iOS.

+4
source share
1 answer

It sounds like you already answered your question, but to confirm your suspicion, usually you first try to retrieve an object from NSMutableSet using [myCache anyObject] . If you successfully retrieve an object this way, be sure to remove it from the set so that it does not catch again. On the other hand, if -anyObject returns nil , then there are not enough cached objects in the cache for what you need, so you need to create a new one (and be sure to return it to the cache when you are "Done").

This is only one way to accomplish what you are shooting.

Make sense?

+1
source

Source: https://habr.com/ru/post/1333959/


All Articles