1

如果我使用此代码没关系,我只能在 1 行中添加 1 个复选标记,但在 2 个部分中,但我需要在每个部分中添加 1 个复选标记。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{

    int newRow = [indexPath row];
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; 

    if(newRow != oldRow)
    {
        UITableViewCell* newCell = [tableView cellForRowAtIndexPath:indexPath];
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;

         UITableViewCell* oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
        oldCell.accessoryType = UITableViewCellAccessoryNone;
        lastIndexPath = indexPath;
    }
    [tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:YES];
}

如果我用这个

if (indexPath.section == 0);

对于每个部分,它都不起作用。

感谢阅读

4

0 回答 0