2016-04-29 3 views
2

Voici mon code.Am très nouveau à Xcode.When je tape sur la cellule tableview suis UIActionSheet. Pour rejeter UIActionSheet j'ai utilisé UITapGestureRecognizer.Il ne fonctionne pas pour moi.Comment rejeter la feuille d'actions dans tableviewcell quand je tape sur la vue dans ios

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; 
    UILabel *lbl = (UILabel *)[cell.contentView viewWithTag:2]; 
    NSLog(@"cell text label =%@",lbl.text); 
    _StoreNameobj = lbl.text; 


    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Store Maintenance Action" 
                  delegate:self 
                cancelButtonTitle:cancelTitle 
               destructiveButtonTitle:nil 
                otherButtonTitles:@"Show Store Details",@"Navigate to Store",@"Edit Store Nickname",@"Delete Store", nil]; 


    actionSheet.userInteractionEnabled = YES; 

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOut:)]; 
    [lbl addGestureRecognizer:tapGesture]; 
    [cell.contentView addSubview:lbl]; 
} 

    - (void)tapOut{ 
    //dismiss the action sheet here 
    [actionSheet removeFromSuperview]; 
} 

Toute aide est appréciable.Merci à l'avance!

+0

pourquoi vous ne pouvez pas utiliser '' didSelectRow' ou UIButton' de rejeter – Shubhank

+0

Il n'y a pas besoin de prendre le geste du robinet sur la feuille d'action. Son comportement par défaut est de le rejeter au clic. – Lion

+0

Comment utiliser didSelectRow de rejeter ActionSheet @Shubhank – srinitha

Répondre

0

Je pense que vous n'avez pas besoin de supprimer manuellement la feuille de calcul. Par défaut, la feuille d'actions est résignée lors du clic. il n'y a pas besoin de prendre le geste de tabulation je pense.

Afficher actionsheet comme,

[actionSheet showInView:self.view]; 

donc quand vous clik sur un bouton, il dissmiss automatiquement

0

Pour afficher UIActionSheet sur UITableViewCell appliquer ce code

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Your Title:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: 
         @"button title1", nil]; 

    [popup show]; 
} 

ajouter TapGesture

- (void)viewDidLoad { 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view. 
     UITapGestureRecognizer *tapp = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(HideActionSheet:)]; 

     [tapp setNumberOfTapsRequired:1]; 
     tapp.cancelsTouchesInView = NO; 
     [self.view.window tapp]; 
     [tapp release]; 
} 

Code HideActionSheet:

- (void) HideActionSheet:(UITapGestureRecognizer *)sender 
{ 
    if (sender.state == UIGestureRecognizerStateEnded) 
    { 
     CGPoint location = [sender locationInView:nil]; 
     if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil]) 
     { 
      [self.view.window removeGestureRecognizer:sender]; 
      [self dismissModalViewControllerAnimated:YES]; 
     } 
    } 
} 
+0

je devrais mettre en œuvre le code ci-dessus dans didSelectRowAtIndexPath ou méthodes cellForRowAtIndexPath de Tableview @Pratap – srinitha

+0

chèque réponse mis à jour tapgesture créez dans ViewDidLoad –

+0

J'ai besoin de Actionsheet quand je clique sur la cellule tableview @Pratap – srinitha