2010-04-19 4 views
0

J'essaie d'envoyer une ActionSheet à partir d'un bouton.Passage de valeurs d'UIButton à une feuille UIAction

Je ne peux pas utiliser la propriété tag car elle est utilisée pour autre chose.

J'ai déclaré myIndexRow comme une variable d'instance et ont:

NSInteger myIndexRow = indexPath.row; 
    [deleteButton addTarget:self action:@selector(showDeleteSheet:) forControlEvents:UIControlEventTouchUpInside]; 

    deleteButton.myIndexRow = myIndexRow; 

mais je reçois le « Demande de membre « myRow » est quelque chose pas une structure ou d'une union »

Il est quelque chose d'évident me manque ici.

+0

Échec ci-dessus. Voir la réponse ci-dessous pour un moyen de le faire. –

Répondre

1

jamais pensé que je vais répondre à ma propre question sur le SO, mais ici va:

Accès de superview du superview et interroger la section indexPath et les propriétés de ligne a fait l'affaire.

Dans la cible du bouton:

-(void)showDeleteSheet:(id)sender { 

NSIndexPath *indexPath = [table indexPathForCell:(UITableViewCell *)[[sender superview] superview]]; 

    NSInteger currentSection = indexPath.section; 
    NSInteger currentIndexRow = indexPath.row; 

    //form the actionSheet 
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Delete this item?" 
                 delegate:self 
               cancelButtonTitle:@"Cancel" 
              destructiveButtonTitle:@"Delete" 
               otherButtonTitles:nil];       
    actionSheet.tag = currentIndexRow; 
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault; 
    [actionSheet showInView:self.view]; 
    [actionSheet release]; 
} 

Puis dans la méthode de clickedButtonAtIndex de actionSheet je reçois la ligne que je besoin:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 

    if (buttonIndex == 0) 
     { ... doSomethingWith: actionSheet.tag } 
    else 
     { ... user pressed cancel } 
} 

Une partie de la réponse a été trouvée in another post and et le reste here

Questions connexes