views:

221

answers:

1

Hey everyone,

I am learning about using the checkmark cell accessory and am wondering why the contents of my cell is disappearing when toggling it.

Here is my code:

+ (void) toggleCheckmarkedCell:(UITableViewCell *)cell {
    if (cell.accessoryType == UITableViewCellAccessoryNone)
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    else
        cell.accessoryType = UITableViewCellAccessoryNone;
}

And here is didSelectRowAtIndexPath:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

[RootViewController toggleCheckmarkedCell:cell];

The checkmark is toggling on/off and is visible but the main contents of the cell disappears. Can anyone explain why this is happening?

Thank you,

+2  A: 

Your cells aren't disapearing, they just change selectionStyle. For example you have text in textLabel with black font. When you click cell, you select it, and cell.selected property changes to YES with automatic change of textLabel font color to white and cell background to blue. Then you change selectionStyle to UITableViewCellSelectionStyleNone and background color of cell changed to white. But cell still remains selected and text color still white too. White color on white background simply invisible.

To fix this problem you shoud change selected property rather then selectionStyle. Or use custom cells.

Vladimir
Thanks, but if I add cell.selected = NO;, the cell goes blue for a second, then back to white. How can I stop the blue from appearing at all?
barfoon
set: cell.selectionStyle = UITableViewCellSelectionStyleNone; when you create cell.and in didSelectRowAtIndexPath set only selected = NO;
Vladimir
Thanks very much,
barfoon