0

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");
}

}
kAiN
  • 2,559
  • 1
  • 26
  • 54
  • Do you want to get all the selected rows? or just one? the one that got clicked? – Astri Nov 14 '13 at 19:54
  • I wish that when I click on Send (nell'alertView) data that are saved are those of the correct cell is selected. – kAiN Nov 14 '13 at 19:55

1 Answers1

1

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");
    }
}
Astri
  • 575
  • 4
  • 10
  • I tried but does not work ... I saved the data from the first cell in the TableView and not the selected cell ... : (I do not understand – kAiN Nov 14 '13 at 20:01
  • I need more information. self.Utenti contains the data that is being populated in your tableView? Do you have more than 1 section? – Astri Nov 14 '13 at 20:16
  • Your method is how I would have done ... The logical way is right .... Self.Utenti is the array that contains all the objects taken from the database and displayed in the TableView ... is a list of subscribers to the app .... the TableView is simple ... no additional sections – kAiN Nov 14 '13 at 21:34