views:

394

answers:

1

Hi,

I have the same question problem as described here http://stackoverflow.com/questions/2286669/iphone-how-to-purge-a-cached-uitableviewcell

But my problem can't be solved with "resetting content".

To be precise - I use a custom cell (own class). While running the application it is possible that I have to use a different "cell type". It's the same class - but it has (a lot of) differnt attributes. Of course I could always reset all the things at "PrepareForReuse" but that's not a good idea I guess (there are a lot things to reset).

My idea - I do all these things in the constructor of the cell. And all the rows will use this "type of cell" later. When the (seldom) situation comes that I have to change the look of all rows I create a new instance of this kind of cell with different settings. And now I want to replace the queued cell with this new one.

I tried it with simply calling the constructor with the same cellidentifier (in the hope it will replace the existing one) but that doesn't work.

I also didn't find a "ClearReusableCells" or something like this.

Is there a way to clear the cache - or to remove / replace a specific item?

Manfred

+2  A: 

Create each cell type (even if they use the same cell class) using a different identifier. So if you have 2 cell types, define 2 identifiers and keep them separate.

I'm not sure where your problem is. You have a bunch of cells, with appearance A, then the user takes some action and they need to become appearance B. If you call reloadData or one of the more granular methods, your datasource will be called again for cellForRowAtIndexPath. Just implement this method to segregate the two cell types.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString* identifier = which mode are we in
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier]; // Will return nil if we haven't got this cell
    if( !cell ) {
        // Create different cell type based on the identifier   
    }
    return cell;
}
Steven Canfield
Which does still not solve the problem - when I call tv.DequeueReusabelCell it will return what it does now.My problem is how to get the new cell (no matter if the same or other class) from that call.Setting a new identifier would help - and produce orphans :(
ManniAT
First of all thank you for your will to help me, and the time you spent witch my question.You'r asking where my problem is: - it's resource usage. I change my mode - and from that moment on a "heavy - no longer used" cell hangs around in the TV-cache. But it seems as if Apple doesn't provide a "clearing mechanism" - so I guess I have to accept this. That means I'll further work with my current solution (which is like you also wrote) a change of the identifier.THANKS again Manfred
ManniAT
After you return a cell from cellForRowAtIndexPath, it's up to the tableview to manage that memory. The tableView will free it at some point in the future, but it's not your concern (in general). Only worry about objects you have a reference to ;)
Steven Canfield
Ah, I didn't know that Steven. I always thought if I ever cache a cell it will be there till...app ends.
ManniAT