the UIActionSheet crashes after it appears the second time through..
.H file
..UIActionSheetDelegate>{
UIActionSheet *popupQuery;
}
@property (nonatomic, retain) UIActionSheet *popupQuery;
.M file
-(IBAction)showActionSheet:(id)sender {
if (popupQuery.visible) {
NSLog(@"popupQuery isVisible");
[popupQuery dismissWithClickedButtonIndex:-1 animated:YES];
return;
}else{
popupQuery = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Readibility" otherButtonTitles:@"Email URL", @"Print", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
//[popupQuery showInView:self.view];
[popupQuery showFromBarButtonItem:actionButton animated:YES];
[popupQuery release];
}
}
When you release
popupQueryafter showing it fromactionButton, you relinquish ownership on the object. If the object gets deallocated thenpopupQuerywill point to a deallocated object which when you dopopupQuery.visiblemight give you a crash. Since you have it as a property, you can do this –Remove the
releasestatement at the end. Now the object will be valid when youpopupQuery.visibleorself.poupQuery.visibleIn this case, you will have the ownership and you can safely access the object.