views:

782

answers:

2

Okidoke. Here's my problem: I have a series of complex UITableViewCells set up to display stories from a news feed (yawn). What I want to happen, is for the cell background image and height to change on selection (as a means of marking that the story has been read).

Now, prior to setting up dequeueing, I was able to do this with a simple [self.tableView reloadData]. That seems to be a no-go with dequeued cells; reloading the table view does not redraw the cells to match their changed state.

I've tried reloadRowsAtIndex- and while this works - beautifully - for the first cell a user clicks on, it goes wonky after that point: sometimes the cell reloads correctly, sometimes not.

Obviously, each story is an NSMutableDictionary object. I'm using an NSNumber object to track whether or not a story has been read.

I would post the code, and I will if anyone asks, but I'm looking for a generic solution that could be implemented in any UITableViewController (share the love).

So, simply put: how does one reliably redraw complex cells on selection?

A: 

Try giving each cell a unique ID in order for dequeuing to work, your cells should be coming back with their changed states if you use a unique id for each cell, so 20 cells = 20 ids, hope this helps

Daniel
A: 

Assuming you have the index path, you can access the cell and manipulate it directly:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  // handle the selection...

  UITableViewCell *cell = [tableView cellForRowAtIndexPath: indexPath];
  if (nil != cell) {
    //
    // now update the cell to reflect the new state
    //
  }
}
dmercredi
Thank you, Daniel and dmercredi - both. I found a place for each of your solutions in different places in my app.
nzeltzer