UITableview accessory type disappear while scrolling

前端 未结 3 1524
情书的邮戳
情书的邮戳 2021-01-13 11:26

I have made a tableView in which i need to select multiple options. The options are selected but when i scroll the table view the check mark option get disappear and some ot

3条回答
  •  醉梦人生
    2021-01-13 12:13

    You need to check the cell is already selected or not in the cellForRowAtIndexPath method. This issue is happening because tableView re-uses the cells. Please write the below code in your cellForRowAtIndexPath method, it'll solve the issue.

    NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:indexPath.row];
    if ( [selectedCells containsObject:rowNsNum]  )
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    

提交回复
热议问题