views:

74

answers:

2

Is there a way to tell a UITableView to preload all rows?

The tableView is supposed to show several comments (up to 80 comments).

So my CommentCell uses a Setter to adapt the cell to a specific comment.

-(void)setComment:(Comment *)newComment {
 if (newComment != comment) {
     [comment release];
        comment = [newComment retain]; 
       /*
        * set the cells view variables here
        */
    }
}  

This specific setter takes quite a bunch of processing resources and scrolling gets kinda laggy.

I am using a comment-specific reuseIdentifier instead of a static cellIdentifier when calling

dequeueReusableCellWithIdentifier:

in order to assure, that "newComment" equals the old "comment".
And in fact this does work great when scrolling over cells which have already been loaded.

But when scrolling through the comments for the first time, it still lags like hell.

Which leads me to my question:
Is there a way to tell the tableview to preload all cells? (which I doubt)
or
Do I have to implement my own cache instead of relying on "dequeueReusableCellWithIdentifier:"?

+1  A: 

No, you have to preload your data in your dataSource. Just put everything you need in an array and fill the table's cells from that array of preloaded objects.

Nikolai Ruhe
+2  A: 

Keep in mind that your comment specific reuseIdentifier could be what is causing everything to go slow (or at least, it isn't helping). The reason we use reuseIdentifier for UITableViewCells is because if you try to allocate a new cell every time you need one it isn't as performant as if you can just reuse one that was already made.

I'd recommend pre-computing your comments so you can just set properties of your cells and reusing cells after they scroll off the tableview.

Terry
I normally do use cell-reuseIdentifiers and this is case was no exception, but after hours of testing, debugging and rewriting it became clear, that the lags resulted from a combination of allocating new cells and usage of the setter.That's why I tried several combinations and it clearly showed that the setter even alone creates horrible lags (I exaggerate a little, but these lags really suck).That's why I can't use a cell-specific reuseIdentifier.
Infinite