2010-10-01 14 views
2

J'ai un "encore" ;-) un problème que je ne peux pas résoudre.Dismiss UI action sheet - crash

Mon application se lance sur une tableView. Lorsque je sélectionne une cellule, je vais dans le "detailView". Sur ce point de vue j'ajouter deux boutons de la barre d'outils de cette façon:

UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 115, 44.01)]; 
// tab where buttons are stored 
NSMutableArray* buttons = [[NSMutableArray alloc] init];  
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(nextEdit)]; 
UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(popupActionSheet)]; 
btn.style=UIBarButtonItemStyleBordered; 
btn2.style = UIBarButtonItemStyleBordered; 
[buttons addObject:btn]; 
[buttons addObject:btn2]; 
// add buttons to the toolbar 
[tools setItems:buttons animated:YES]; 

// add buttons within "tools" to the view 
    UIBarButtonItem *btn3 = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
    self.navigationItem.rightBarButtonItem = btn3; 
    [buttons release]; 

    [btn release]; 
    [btn2 release]; 
    [btn3 release]; 
    [tools release]; 

Une fois que je clique sur le bouton de la corbeille que j'appelle la méthode « popupActionSheet » pour faire pop-up « supprimer confirmation » apparaît:

-(void)popupActionSheet { 
isActiveSupr=(BOOL)YES; 
UIActionSheet *popupQuery = [[UIActionSheet alloc] 
          initWithTitle:@"Delete ? " 
          delegate:self        
          cancelButtonTitle:@"Cancel" 
          destructiveButtonTitle:@"Confirm" 
          otherButtonTitles:nil ,nil]; 

popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
[popupQuery showInView:self.tabBarController.view]; 
[popupQuery release]; 
} 

Puis, quand je clique sur destructiveButtonTitle: @ « confirmer » le « confirmer la suppression » Rejette popup et il appelle:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    if(isActiveSupr==TRUE) 
{ 
    if(buttonIndex==0) 
    { 
     [self send_requestDelete];    
    } 
} 
} 

- (void)send_requestDelete: 
{ 
... //nothing to do with popup 
[self showActionsheet:@"Demand deleted"]; 
[self.navigationController popToRootViewControllerAnimated:YES]; 
... // nothing to do with popup 
} 

-(void) showActionsheet :(NSString *)msg 
{ 
UIActionSheet *popupQuery = [[UIActionSheet alloc] 
          initWithTitle:msg 
          delegate:self        
          cancelButtonTitle:@"OK" 
          destructiveButtonTitle:nil 
          otherButtonTitles:nil ,nil]; 
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
[popupQuery showInView:self.tabBarController.view]; 
[popupQuery release]; 
} 

Alors que je retourne sur mon tableViewController le po pup ("showActionsheet: @" Demande supprimée "];") apparaît.

Si je clique sur "OK", mon application tombe en panne. Si je désactive cette fenêtre ("showActionsheet") tout va bien. C'est comme si je retournais à la tableView, la popup qui était appelée dans "DetailView" n'existe plus.

Thx pour l'aide.

+0

Pouvez-vous afficher le journal de bord? – kthorat

Répondre

0

Tout d'abord, avez-vous mis des points d'arrêt sur les exceptions objc_exception_throw et [élévation NSException]?

aussi parce que le ActionSheet est ajouté à la sous-vue et directement après que vous faites ceci:

[self.navigationController popToRootViewControllerAnimated:YES]; 

Le actionsheet n'est pas une boîte de dialogue modale ou quoi que ce soit et il ne bloque pas appeler d'autres fonctions en attendant.

Ce qui pourrait aider est si vous avez fait quelque chose comme ce qui suit:

-(void)popupActionSheet 
{ 
    isActiveSupr=(BOOL)YES; 
    UIActionSheet *popupQuery = [[UIActionSheet alloc] 
           initWithTitle:@"Delete ? " 
           delegate:self        
           cancelButtonTitle:@"Cancel" 
           destructiveButtonTitle:@"Confirm" 
           otherButtonTitles:nil ,nil]; 
    popupQuery.tag = 1; 
    popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
    [popupQuery showInView:self.tabBarController.view]; 
    [popupQuery release]; 
} 

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    if (actionSheet.tag == 1) 
    { 
     if(buttonIndex==0) 
     { 
      [self send_requestDelete];    
     } 
    } 
    else if (actionSheet.tag == 2) 
    { 
     [self.navigationController popToRootViewControllerAnimated:YES]; 
    } 
} 

- (void)send_requestDelete: 
{ 
    ... //nothing to do with popup 
    [self showActionsheet:@"Demand deleted"]; 
    ... // nothing to do with popup 
} 

-(void) showActionsheet :(NSString *)msg 
{ 
    UIActionSheet *popupQuery = [[UIActionSheet alloc] 
           initWithTitle:msg 
           delegate:self        
           cancelButtonTitle:@"OK" 
           destructiveButtonTitle:nil 
           otherButtonTitles:nil ,nil]; 
    popupQuery.tag = 2; 
    popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
    [popupQuery showInView:self.tabBarController.view]; 
    [popupQuery release]; 
} 

De cette façon, la méthode didDismissWithButtonIndex savoir qui actionsheet a été effectivement utilisé et ce que l'action suivante devrait être.

Vous ne devriez jamais supprimer un affichage lorsque vous travaillez dessus, comme vous l'êtes.

+0

thx Wim. Ça fonctionne bien. Maintenant, la vue est seulement poussée quand je rejette le deuxième popup. – wallou

+0

Ok, alors votre problème est résolu? –

+0

un peu en retard, mais oui c'est. – wallou