UITableViewCell Accessory Type Checked on Tap & Set other unchecked

后端 未结 9 2269
小蘑菇
小蘑菇 2020-12-03 03:02

I am confused a little bit about settings table view cell accessories.

I have fixed two sections in my table

  • Home
  • Office

What I

9条回答
  •  隐瞒了意图╮
    2020-12-03 03:36

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

    also you need to remove the checkmark accessory on cellForRowAtIndexPath

    if ([selectedOptionsArray indexOfObject:cell.textLabel.text] != NSNotFound) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }else{
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    

提交回复
热议问题