从表视图iOS Parse.com中删除行

从表视图iOS Parse.com中删除行,ios,objective-c,uitableview,parse-platform,pfquery,Ios,Objective C,Uitableview,Parse Platform,Pfquery,我正试图用下面的代码从我的tableView中删除选定的行 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView deselectRowAtIndexPath:indexPath animated:NO]; PFUser *user = [self.friends objectAtIndex:indexPath.ro

我正试图用下面的代码从我的tableView中删除选定的行

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];

    PFUser *user = [self.friends objectAtIndex:indexPath.row];

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Remove user"]
                                                        message:[NSString stringWithFormat:@"Are you sure you want to remove user?"]
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"OK", nil];
    [alertView show];
    [self.tableView reloadData];
}

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    PFUser *user = [self.friends objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
    NSLog(@"%@",user);
    PFRelation *friendsRelation = [[PFUser currentUser] relationForKey:@"friendsRelation"];

    if( 0 == buttonIndex ){ //cancel button

    } else if ( 1 == buttonIndex ){

        [friendsRelation removeObject:user];

        } else {

        }

        [[PFUser currentUser] saveInBackgroundWithBlock:^(BOOL succeed, NSError *error) {

            if (error) {
                NSLog(@"error %@ %@", error, [error userInfo]);
            } else {

            }

        }];

}
而现在发生的一切就是最上面的一行不断被删除,而不是我选择的那一行?请帮助我获取我选择的行

编辑:


这一行导致了问题,无法获取所选行?

我只需要在标题中声明PFUser*user并将其用作全局变量,然后将其传递到
[friendsRelation removeObject:]作为self.user


希望这对其他初学者有所帮助。

既然您
取消了rowatinexpath
那么您希望
indexPathForSelectedRow
如何返回有用的内容?@luk2302在删除
取消rowatinexpath
PFUser *user = [self.friends objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];