Вопрос

in tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath I inserted a alertView which contains a text that changes depending on the cell clicked ..

The action of the button "SEND" nell'alertView must save the contents of the label present in the selected cell.

P.S. I am using Parse.com

Until now everything works but I only have one problem, the data that are saved are incorrect because they are not the data of the selected cell but data from the first cell in the table view ... I do not save more .. only this ..

Nell'IndexPath'm doing something wrong? can you help me to recognize the selected cell 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");
}

}
Это было полезно?

Решение

If i understood correctly:

Create an instance variable:

NSInteger _clickedCell;

then

- (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");
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top