开发者

Implement a system similar to the way UITableView dequeues cells already created

I need to implement a grid for displaying some view entities on the iPad. To get the most out of the SDK I thought I would use a UITableView to keep track of my rows and then implement some sort of enumerator to return the correct columns to put into my cells.

The enumerator is working out just fine. I just pass the tableViews viewController a one-dimensional array and the enumerator splits it up into a "pseudo two dimensional set", however, I would like to make the grid use an approach similar to the UITableViews for both rows and columns:

[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

As it is now I build 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 something like:

columnsForRowAtIndexPath:

and have it work like the cellForRowAtIndexP开发者_如何学Pythonath..

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

-

I can't really figure out if the tableView copies the cells or builds new ones using NSCoding to return cells with a minimum of overhead. Guess NSMatrix would be really nice to have in iOS.


Looks like you already answered your own question, but just to confirm your suspicion, typically you would first attempt to retrieve an object from an NSMutableSet with [myCache anyObject]. If you successfully retrieve an object this way, make sure to remove it from the set so it doesn't get grabbed again. On the other hand, if -anyObject returns nil, then the cache doesn't have enough cached objects for what you need, so you need to create a new one (and make sure you put it back into the cache when you're done).

This is just one way to accomplish what you're shooting for.

Make sense?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜