【发布时间】:2016-01-17 13:06:32
【问题描述】:
我正在尝试使用以下代码从我的 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]];
此行导致问题并且未获得选定行?
【问题讨论】:
-
既然你是
deselectRowAtIndexPath,你怎么期待indexPathForSelectedRow返回任何有用的东西? -
@luk2302 删除
deselectRowAtIndexPath后我仍然遇到同样的问题
标签: ios objective-c uitableview parse-platform pfquery