views:

172

answers:

1

I am really puzzeled by this one. I have set up two UIActionSheets in my application. They work perfectly fine until you use the cancel button in the UIActionSheets.

When i navigate away from the page the UIAactionSheet returns too it crashes my app.

Does anyone have any ideas as too why?

-(IBAction) phoneButtonClicked:(id)sender
{
// open a dialog with just an OK button
phoneActionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                    delegate:self cancelButtonTitle:@"Cancel" 
                                                    destructiveButtonTitle:nil 
                                                    otherButtonTitles:[NSString stringWithFormat:@"Phone: %@",phone],nil];
phoneActionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[phoneActionSheet showInView:self.view];    // show from our table view (pops up in the middle of the table)
[phoneActionSheet release]; 
}

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

if (actionSheet == phoneActionSheet) {

    if(buttonIndex == 0){
            NSString *callPhone = [NSString stringWithFormat:@"tel:%@",phone];
            NSLog(@"Calling: %@", callPhone);
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
    }
}

}
A: 

I would suggest not releasing the phoneActionSheet in phoneButtonClicked. I suspect you might be trying to do something with a bad pointer. Another good help is to use NSZombieEnabled.

Daniel Blezek
Nothing was logged in the console but removing the release command worked.
The sheet probably leaks without that release. Each time, you invoke phoneButtonClicked, you create a new sheet that you are no longer releasing. However, you need to release it after the sheet has been dismissed, not straight after it has been created.
JeremyP
I typically release the action sheets in the clickedButton and/or canceled call. This isn't the best, but it keeps their lifetimes short.
Daniel Blezek