0
votes

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];
}
}
6
Have you tried to skip (or emulate with a button) the mail passage and then tried to pop to root view controller (so calling directly the popToRootViewController method). At least you can see if the issue is due to the root controller that has been over realesed.viggio24
May be rootviewcontroller object have releasedTendulkar
When i skip the mail, and just call popToRoot on last view.. it wil gif me the error “EXC_BAD_ACCESS”, but i didnt get it in NSZombie:STh3noon
i'm confused, how do i check if it is released? and how do i fix it, if it is..Th3noon
Finnaly got the answer:) I store information in the delegate. After doing that i released.. Guess i shouldn't do thatTh3noon

6 Answers

0
votes

[self.navigationController popToRootViewControllerAnimated:NO];

0
votes

Comment out the line of code shown below:

//  [self dismissModalViewControllerAnimated:YES];
0
votes

I had issues with popToRootViewController:animated: being called within a UIAlertView callback in iOS4 (but not iOS5), so instead I posted a notification within the callback that was received by a singleton class and the singleton called popToRootViewController:animated:

0
votes

Check if you have a release or autorealease in your previous ViewControllers (especially to the ViewController that sends you to the last viewController) right before the

[self.navigationController pushViewController:yourViewController animated:YES];

You may have something like:

vController = [[YourViewController alloc] initWithNibName:@"HighScoreViewController" bundle:nil] autorelease];

so you'll have to remove autorelease

0
votes

In terms of saving the app from crashing this code snippet should make it.

if([navigationController respondsToSelector:@selector(popToRootViewControllerAnimated:)]) {
            [navigationController popToRootViewControllerAnimated:NO];
}

But still need to find the reason behind the screen why the navigationController is not responding to selector in order to make pop to root view controller happen when needed.

-1
votes

Try [self popToRootViewControllerAnimated:NO];