我有多个视图的基于导航的应用程序。当我到达最后一个视图时,应用程序将发送一封电子邮件(使用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];
}
}
答案 0 :(得分:0)
[self.navigationController popToRootViewControllerAnimated:NO];
答案 1 :(得分:0)
注释掉下面显示的代码行:
// [self dismissModalViewControllerAnimated:YES];
答案 2 :(得分:0)
我在iOS4(但不是iOS5)的UIAlertView回调中调用popToRootViewController:animated:
时遇到了问题,所以我在回调中发布了一个单例类接收的通知和名为{{1}的单例}
答案 3 :(得分:0)
检查您之前的ViewControllers中是否有发布或自动回复(特别是发送到最后一个viewController的ViewController)
[self.navigationController pushViewController:yourViewController animated:YES];
你可能有类似的东西:
vController = [[YourViewController alloc] initWithNibName:@"HighScoreViewController" bundle:nil] autorelease];
所以你必须删除自动释放
答案 4 :(得分:0)
就保存应用程序免于崩溃而言,此代码段应该成功。
if([navigationController respondsToSelector:@selector(popToRootViewControllerAnimated:)]) {
[navigationController popToRootViewControllerAnimated:NO];
}
但是仍然需要找到屏幕背后的原因导致为什么导航控制器没有响应选择器,以便在需要时使弹出到根视图控制器。
答案 5 :(得分:-1)
尝试[self popToRootViewControllerAnimated:NO];