我正在尝试使用以下代码
从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 = [self.friends objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
此行导致问题而未获得选定的行?
答案 0 :(得分:0)
我只需要在标头中声明PFUser * user并将其用作全局变量,然后将其作为self.user传递给[friendsRelation removeObject:];
。
希望这有助于其他初学者。