0

私は2つの配列を持っています。各配列はセクションを取得します。ユーザーが行をスワイプして削除を選択すると、右側のセクションの適切な行を削除する必要があります。コードを変更して、正しいセクションで削除するにはどうすればよいですか。これはこれまでの私のコードです。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //remove the deleted object from your data source.
        //If you're data source is an NSMutableArray, do this
        if (self.numberOfSections == 1)
        {
            [self.playerNames removeObjectAtIndex:indexPath.row];
        }
        else
        {
            //code here needs to determine which section needs to be deleted
        }
        [self.tableView reloadData];
    }
}
4

3 に答える 3

1

コード スニペットを次に示します。

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
    forRowAtIndexPath:(NSIndexPath *)indexPath {
    // If row is deleted, remove it from the list.
    if (editingStyle == UITableViewCellEditingStyleDelete) {
          NSInteger row = [indexPath row];
          [tableDataSource removeObjectAtIndex:row];      
          [tableView reloadData];
    }
}

このAppleドキュメントも参照してください

于 2013-03-20T08:17:35.500 に答える
0
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //remove the deleted object from your data source.
        //If you're data source is an NSMutableArray, do this
        if (self.numberOfSections == 1)
        {

            [self.playerNames removeObjectAtIndex:indexPath.row];
        }
        else
        {
             if (indexPath.section == 0)
             {
                 [self.team1 removeObjectAtIndex:indexPath.row];
             }
            else
            {
                [self.team2 removeObjectAtIndex:indexPath.row];
            }
        }
        [self.tableView reloadData];
    }
}
于 2013-03-20T08:18:49.273 に答える