views:

49

answers:

1

Hi,

I have a UITableView that I want to use to allow multiple selections. I have rolled together most of the functionality, but am having one small problem.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"Selected");
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

    if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) {
        [selectedCell setBackgroundColor:[UIColor grayColor]];
        [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
        [[selectedCell textLabel] setTextColor:[UIColor whiteColor]];
    } else {
        [selectedCell setAccessoryType:UITableViewCellAccessoryNone];
        [selectedCell setBackgroundColor:[UIColor clearColor]];
        [[selectedCell textLabel] setTextColor:[UIColor blackColor]];
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

This is the code I am using to keep the cell selected, however when the user taps on the cell, the aaccessory view turns white and then turns back to blue.

What is the best way for me to keep the accessory view white?

Thanks

+1  A: 

I believe easy way to achieve this is by creating custom imageview with checkmark image(you need to get it as white checkmark) and set it as accessory view when selected.

This will avoid the standard behavior of the accessoryview and achieve your goal.

SegFault