How to properly toggle UITableViewCell's accesoryType on cell selection/deselection?

前端 未结 4 1736
野性不改
野性不改 2021-01-03 06:08

I\'m trying to toggle accesoryType when a table cell is selected/deselected... the behavior should be: tap -> set accessoryType to UITableViewCellAc

4条回答
  •  一整个雨季
    2021-01-03 06:38

    Try this if this is what you want

     - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
        {   
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            if (cell.accessoryType == UITableViewCellAccessoryCheckmark)
            {
                cell.accessoryType = UITableViewCellAccessoryNone;
            }
            else
            {
                cell.accessoryType = UITableViewCellAccessoryCheckmark;
            }
        }
    

提交回复
热议问题