iOS UITableViewCellAccessoryCheckmark Visible ob every scroll

后端 未结 4 1302
甜味超标
甜味超标 2021-01-28 02:50

I have a list which I have using as a check boxes. I have enable or disable Check mark on row on select. But when I scroll the list its make mark row after every 10 rows.

<
4条回答
  •  情书的邮戳
    2021-01-28 03:04

    UItableView reuses the cell in every scroll so using condition as per accessory type is not a good practice. You can Create an NSMutableArray with selected items and Check as per the Condition below.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        }
        if ([selected containsIndex:indexPath.row]) {
            [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
        } else {
            [cell setAccessoryType:UITableViewCellAccessoryNone];
        }
        // Do the rest of your code
        return cell;
    } 
    

    in didSelectrowAtindexpath method you can Add and remove the Selected items.

提交回复
热议问题