Why are the contents of my UITableViewCell disappearing?
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:UITa开发者_开发问答bleViewCellSelectionStyleNone];
[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,
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.
精彩评论