0

我得到了具有多个视图的基于导航的应用程序。当我到达最后一个视图时,应用程序将发送一封电子邮件(使用 MailComposer)。之后就想回到家中查看。

一切正常,但是当我尝试使用以下方法返回主页时: [self.navigationController popToRootViewControllerAnimated:YES]; 应用程序将崩溃并显示“EXC_BAD_ACCESS”错误。我知道我可以使用 NSZombie 进行调试,但是当我尝试在 NSZombie 中获取错误时,不会出现错误。

我怎样才能解决这个问题?或者有没有办法只释放所有视图并重新加载第一个视图?任何提示或任何可以帮助我的东西都会很棒。这是一些代码:

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

6 回答 6

0

注释掉如下所示的代码行:

//  [self dismissModalViewControllerAnimated:YES];
于 2011-08-09T11:16:39.883 回答
0

[self.navigationController popToRootViewControllerAnimated:NO];

于 2011-08-09T11:10:20.060 回答
0

popToRootViewController:animated:我在 iOS4(但不是 iOS5)的 UIAlertView 回调中被调用时遇到了问题,所以我在单例类接收的回调中发布了一个通知,并且单例调用popToRootViewController:animated:

于 2012-06-03T16:02:30.423 回答
0

检查你之前的 ViewController 中是否有 release 或 autorealease(尤其是发送到最后一个 viewController 的 ViewController)。

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

你可能有类似的东西:

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

所以你必须删除自动释放

于 2013-12-18T09:33:32.143 回答
0

为了使应用程序免于崩溃,这个代码片段应该可以做到。

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

但是仍然需要找到导航控制器没有响应选择器的屏幕背后的原因,以便在需要时弹出到根视图控制器。

于 2018-06-14T01:46:13.300 回答
-1

尝试 [self popToRootViewControllerAnimated:NO];

于 2011-08-09T11:04:29.470 回答