1

このコードを使用する場合、1 行に 1 つのチェックマークを追加できますが、2 つのセクションに 1 つのチェックマークを追加できますが、各セクションに 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