我有一个允许多个选择的UITableView,但是由于某种原因,当我滚动UITableView时,我在滚动时重复使用UITableViewCellAccessoryCheckmark所做的选择。
这是我正在使用的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.backgroundColor = [UIColor clearColor];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    // Configure the cell...
    cell.textLabel.text = [sortedMachineNames objectAtIndex:indexPath.row];
    return cell;
}
#pragma mark - Table view delegate
// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    [selectedMachinesMArray addObject:cell.textLabel.text];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryNone;
    NSUInteger index = [selectedMachinesMArray indexOfObject:cell.textLabel.text];
    if (index!=NSNotFound) {
        [selectedMachinesMArray removeObjectAtIndex:index];
    }
}发布于 2014-10-20 21:36:01
在cellforIndexAtPath中,检查单元格的当前状态并更改可访问类型的值,如下所示:
if(marked)
     cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
     cell.accessoryType = UITableViewCellAccessoryNone;https://stackoverflow.com/questions/26474556
复制相似问题