views:

26

answers:

1

I have some custom table view cells that takes a while to draw, so the first time you scroll it's not very smooth. After the first scroll, all the views are cached and the scrolling is very smooth.

So what I'm wondering is if I could draw all the cells and cache them before the table view is shown and how I would do that. Would there be a problem if I spawned a thread that drew the cells in the background, so that they likely would be drawn when the table view needs them?

Would I have to set up my own dictionary or could I use the table view's dequeueReusableCellWithIdentifier:?

A: 

I do not know a way to predraw a UIView. A view is only drawn, if it's on the screen. What you could do is to try to draw the contents of the cell to a CGBitmapContext, create a UIImage of that context, and in your actual cell only use an imageview which shows the image.

In this case you would of cause need an external storage for the images. Could be array or dictionary.

tonklon
A UIView has a method called drawRect:. I'm not sure what context it would draw on if you manually called it, but I don't see why it wouldn't be possible to predraw a UIView. My UITableViewCells are only drawn once, so obviously it is possible. The only question is if the SDK allows it.
Erik B