R – Disclosure Indicator disappears

cocoa-touchiphoneuser-interface

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?

Best Solution

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.