[英]Delete row from table view iOS Parse.com
我正在嘗試使用以下代碼從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]];
此行引起問題,但沒有得到選擇的行?
我只需要在標頭中聲明PFUser * user並將其用作全局變量,然后將其傳遞給[friendsRelation removeObject:];
作為self.user。
希望這對其他初學者有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.