0

在 tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath 我插入了一个 alertView ,其中包含一个文本,该文本根据单击的单元格而变化..

按钮“发送”nell'alertView 的操作必须保存所选单元格中存在的标签内容。

PS 我正在使用 Parse.com

到目前为止一切正常,但我只有一个问题,保存的数据不正确,因为它们不是所选单元格的数据,而是表格视图中第一个单元格的数据......我没有保存更多..只有这个..

Nell'IndexPath' 做错了什么?你能帮我识别选中的单元格all'alertview吗?

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{


    if ( buttonIndex ==0) {

        NSLog(@"ritorno");

    }

    else {

        NSArray *indexes = [self.TableView indexPathsForSelectedRows];
        for (NSIndexPath *indexPath in indexes) {

            PFUser *user = [self.Utenti objectAtIndex:indexPath.row];
            PFObject *RichiestaAmicizia = [PFObject objectWithClassName:FF_AMICIZIE_CLASS];
            [RichiestaAmicizia setObject:[PFUser currentUser] forKey:FF_AMICIZIE_DA_USER];
            [RichiestaAmicizia setObject:user forKey:FF_AMICIZIE_A_USER];
            [RichiestaAmicizia setObject:@"In_Attesa" forKey:FF_AMICIZIE_STATO];
            [RichiestaAmicizia saveInBackground];

        }

   NSLog(@"Send");
}

}
4

1 回答 1

1

如果我理解正确:

创建一个实例变量:

NSInteger _clickedCell;

然后

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    _clickedCell = indexPath.row;
    ....
}



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if ( buttonIndex ==0) {

        NSLog(@"ritorno");

    }
    else {
        PFUser *user = [self.Utenti objectAtIndex:_clickedCell];
        PFObject *RichiestaAmicizia = [PFObject objectWithClassName:FF_AMICIZIE_CLASS];
        [RichiestaAmicizia setObject:[PFUser currentUser] forKey:FF_AMICIZIE_DA_USER];
        [RichiestaAmicizia setObject:user forKey:FF_AMICIZIE_A_USER];
        [RichiestaAmicizia setObject:@"In_Attesa" forKey:FF_AMICIZIE_STATO];
        [RichiestaAmicizia saveInBackground];
        NSLog(@"Send");
    }
}
于 2013-11-14T19:58:39.250 回答