I have such error: when I click navigationbar.backItemButton I’m showing UIAlertView with two buttons. When I press on any of them application terminates just with EXC_BAD_ACCESS. Method – (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex don’t called. How can I solve it? Thanx!
//h – file
@interface DetailsTableViewController : UITableViewController <UITextFieldDelegate, UIAlertViewDelegate>
//m – file
- (void)viewWillDisappear:(BOOL)animated
{
//if changes unsaved - alert reask window
if (isDirty)
{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Save changes?"
message:@"Press YES if you want to save changes before exit, NO - other case."
delegate: self
cancelButtonTitle: @"NO"
otherButtonTitles: @"YES", nil];
[message show];
[message autorelease];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex: buttonIndex];
if([title isEqualToString: @"YES"])
{
[self saveBtnUserClick];
}
}
I think the problem is that after you tapped back button your current controller is removed from navigation stack and deallocated, so when alert tries to call its delegate methods it calls them on deallocated object which results in
EXC_BAD_ACCESSerror. To workaround the problem I see 2 obvious options (although there may be better solutions):