views:

1055

answers:

1

I have implemented this below code.

UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath];
UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1];

cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell2.accessoryType = UITableViewCellAccessoryNone;
oldIndexPath1 = indexPath;

But, if I select and then unselect the checkmark, then I cannot select the checkmark anymore.

can you help me?

+1  A: 

I think you're confusing the action of changing the check from one to another and the action of toggling one cell only.

Assuming you only want one checkmarked cell, you could do the following:

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

// tableView:didSelectRowAtIndexPath:

UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath];
UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1];

// Toggle new cell
[MyController toggleCheckmarkedCell:cell];
if (cell != cell2) // only toggle old cell if its a different cell
    [MyController toggleCheckmarkedCell:cell2];
oldIndexPath1 = indexPath;
Nick Bedford