UITableViewCell Accessory Type Checked on Tap & Set other unchecked

后端 未结 9 2250
小蘑菇
小蘑菇 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:14

    Declare one int variable named prev and implement this method:-

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

提交回复
热议问题