Check mark issues in UITableViewCell

I followed this code below.

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

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

      

But, if I select and uncheck the checkbox, then I can no longer select the checkbox.

Could you help me?

+2


source to share


1 answer


I think you are confusing the action of changing the check from one to the other and the action only to switch one cell.

Assuming you only need one check cell, you can 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;

      

+6


source







All Articles