views:

865

answers:

1

I have a UITableView which is using custom UITableViewCells to display some information. I'd like to add a UITableViewCellAccessoryDisclosureIndicator to the cells. Every method that I try successfully adds the chevron, but once the table view scrolls down, they disappear. I'm doing the standard dequeueReusableCellWithIdentifier method, and when I dump out the references to the cells, it's re-using them properly. All of the other data displays fine, it's only the chevrons that disappear.

Things I've tried:

  1. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator];
  2. [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
  3. accessoryTypeForRowWithIndexPath:

Anyone ever have this happen?

+1  A: 

It could happen because you are setting your accessory type outside of the cached cell test:

 static NSString *CellIdentifier = @"UIDocumentationCell";
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
     }
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
     [cell setText:mytext];

The better way, IMHO is like this:

    static NSString *CellIdentifier = @"UIDocumentationCell";
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
     }
     [cell setText:mytext];

Cocoa Touch doesn't seem to want to modify the cached instance of the cell ( subviews ) setting the disclosure indicator in the cell set method results in the indicator being cached, and redrawn once the cell appears again.

Heat Miser
As it turns out, this was not my problem, though I appreciate the best practice. Turns out I had some code that looped through the subviews, removing them. This also happened to remove the indicator, and I was only re-adding the labels.
Brett Bender
Cool... Glad you solved the problem. Thx!
Heat Miser