2013-10-08 3 views
0

Pour chaque cellule de mon UITableView, je configure un objet personnalisé. Comme ceci:Comment passer un objet de la cellule au nouveau contrôleur

// Reference to the turn 
PFObject *turnToPlay = [self.currentUserTurnsToPlay objectAtIndex:indexPath.row]; 

Lorsqu'une cellule est sélectionnée, j'ai besoin de passer cet objet à un nouveau contrôleur de vue.

C'est de mon didSelectRowAtIndexPath

if (indexPath.section == 0) { 
    [self performSegueWithIdentifier:@"takeGameTurn" sender:self]; 
} 

Je me bats pour savoir comment je peux faire référence à mon PFObject créé pour la cellule, pour passer au contrôleur de vue de destination. Je comprends que je passerais ceci à prepareForSegue mais comment puis-je obtenir mon objet de la sélection de cellule.

J'ai une référence à l'indexPath du didSelectRowAtIndexPath mais comment puis-je transmettre cela dans le contrôleur de destination? C'est comme si j'avais besoin d'un autre param dans cette méthode.

Répondre

0

Dans votre prepareForSegue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
     if ([segue.identifier isEqualToString:@"takeGameTurn"]){ 
       NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
       PFObject *turnToPlay = [self.currentUserTurnsToPlay objectAtIndex:indexPath.row]; 

      } 
    } 
+0

Merci, besoin indexPathForSelectedRow, ne savait pas qui était disponible. – StuartM

0

Est-ce votre attribut PFObject de votre cellule? Si oui alors, vous pourriez y

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if([segue.identifier isEqualToString:@"takeGameTurn"]) 
    { 
     YourNextViewController *nextVC = [segue destinationViewController]; 
     NSIndexPath *indexPath; 
     indexPath = [myTableView indexPathForSelectedRow]; 
     MyCustomCell *cell = (MyCustomCell *)[myTableView cellForRowAtIndexPath:indexPath]; 
     nextVC.myPFObject = cell.assignedPfObject; 


    } 
} 
Questions connexes