UIActionSheet cancel button keeps crashing my app

I'm really puzzled by this. There were two UIActionSheets files configured in my application. They work great as long as you don't use the cancel button in the UIActionSheets.

When I navigate away from the page the UIAactionSheet returns too, this crashes my application.

Does anyone have any idea 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]];
    }
}

}

      

+2


a source to share


1 answer


I suggest not releasing phoneActionSheet on phoneButtonClicked. I suspect you might be able to do something with a bad pointer. Another helpful help is using NSZombieEnabled .



+1


a source







All Articles