user337174
user337174

Reputation: 71

UIActionSheet Cancel button keeps crashing my app

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

}

Upvotes: 2

Views: 1028

Answers (1)

Daniel Blezek
Daniel Blezek

Reputation: 4549

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.

Upvotes: 1

Related Questions