I got navigation based application with multiple views. When i got to the last view, the application will send a email (using the MailComposer). After that to would like to return to the home view.
Everything works fine but when i try to return to the home vie by using: [self.navigationController popToRootViewControllerAnimated:YES]; The application will crash and gif me a “EXC_BAD_ACCESS” error. I know i can debug this by using NSZombie, but when i try to get the error in NSZombie the error will not appear.
How can i fix this? Or is there a way to just release all views and reload first view? Any tips or whatever to help me would be great. Here is some code:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
UIAlertView *alert;
case MFMailComposeResultCancelled:
NSLog(@"melding cancelled");
alert = [[UIAlertView alloc]initWithTitle:@"Email afgebroken" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
break;
case MFMailComposeResultSaved:
NSLog(@"melding opgeslagen");
alert = [[UIAlertView alloc]initWithTitle:@"Email opgeslagen" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
break;
case MFMailComposeResultSent:
NSLog(@"melding verzonden");
alert = [[UIAlertView alloc]initWithTitle:@"Email verzonden" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
[self saveMelding];
break;
case MFMailComposeResultFailed:
NSLog(@"melding failed");
alert = [[UIAlertView alloc]initWithTitle:@"Email mislukt te versturen" message:@"probeer het later nog eens" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
break;
default:
NSLog(@"melding niet verzonden");
alert = [[UIAlertView alloc]initWithTitle:@"Email niet verzonden" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
break;
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
NSLog(@"ok");
[self.navigationController popToRootViewControllerAnimated:YES];
}
}