views:

193

answers:

1

Hi guys,

I have a "again" ;-) a problem i can't solve.

My app launches on a tableView. When i select a cell, i go to the "detailView". On this view i add two buttons on the toolbar this way :

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];

Once i click on the trash button i call the method "popupActionSheet" to make "delete confirm" popup appears:

-(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];
}

Then when i click on destructiveButtonTitle:@"Confirm" the "confirm delete" popup dismisses and it calls :

- (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];
}

While i go back on my tableViewController the popup("showActionsheet:@"Demand deleted"];") appears.

If i click "OK" my app crashes. If i disable this pop up("showActionsheet") everything is fine.

It's like while i go back to the tableView , the popup which was called in "DetailView" doesn't exist anymore.

Thx for the help.

A: 

First of all, did you put breakpoints on the objc_exception_throw and [NSException raise] exceptions?

Also because the ActionSheet is added to the subview and directly after that you do this:

[self.navigationController popToRootViewControllerAnimated:YES];

The actionsheet is not a modal dialog or anything and it will not block calling other functions in the meanwhile.

What could help is if you did something like the following:

-(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];
}

This way the didDismissWithButtonIndex method know which actionsheet was actually used and what the next action should be.

You should never be removing a view when you are still working on it, like you are.

Wim Haanstra
thx Wim. It works fine. Now the view is only pushed when i dismiss the second popup.
wallou
Ok, so your problem is solved?
Wim Haanstra