views:

35

answers:

0

I have a transparent table view (UIViewController with subview UIImageView, and another subview UITableView on top of the UIImageView sibling with background = clearColor, UITableViewCells background = clearColor). I also want taps on the cells to toggle the cell's accessoryType between checkmark and none. If I modify the UITableViewCell's accessoryType in tableView:didSelectRowAtIndexPath:, sometimes (30-50% of the time, both on the ios4.1 simulator and on a 3GS iphone running os4.1) when toggling from accessoryType None to accessoryType checkmark the checkmark image is painted against an opaque white background instead of a transparent background. If instead I reload the table (where the accessoryType is also set appropriately for each cell) the transparency works correctly 100% of the time.

Is this a bug? Or is modifying a cell in tableView:didSelectRowAtIndexPath: not the right thing to do, and that row should be reloaded instead? Or is there something else I'm missing?

edit: Here's my didSelectRowAtIndexPath code that shows the undesirable behavior:

edit 2: One more detail of what's happening. It's the very tail end of the deselect animation where the problem happens. The checkmark appears and is displayed properly & transparently while the deselect animation is running and the blue selection is gradually fading out. After the deselect animation finishes and the blue is all gone, maybe 1/10 of a second after the selection color is completely gone, is when the checkmark accessory "automagically" turns opaque with no further user input.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ( self.editing )
    {
    }
    else 
    {
        [self.myTableView deselectRowAtIndexPath:indexPath animated:YES];
        UITableViewCell *cell = [self.myTableView cellForRowAtIndexPath:indexPath];

        // toggle the selection status of the selected row
        //
        NSNumber *rowObj = [NSNumber numberWithUnsignedInt:indexPath.row];
        if ( [self.selectedRows containsObject:rowObj] )
        {
            // currently selected, now de-select
            //
            cell.accessoryType = UITableViewCellAccessoryNone;
            [self.selectedRows removeObject:rowObj];
        }
        else 
        {
            // currently unselected, now select
            //
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
            [self.selectedRows addObject:rowObj];
        }
    }
}