dismissModalViewController然后popViewController

时间:2012-01-17 21:03:11

标签: iphone ios uinavigationcontroller uikit

我一直在寻找解决问题的方法,但到目前为止还没找到任何东西。

我有一个带有UIViewControllers堆栈的UINavigationController(如果相关的话,这都在TabbarController中)。在最后一个ViewController,我想发送一封电子邮件:

MFMailComposeViewController *emailVC = [[MFMailComposeViewController alloc] init];
// fill out emailVC properties ...
[self presentModalViewController:emailVC animated:YES];

然后在电子邮件发送后的委托中,我想关闭电子邮件viewcontroller并弹出NavigationController堆栈中的最后一个viewcontroller:

-(void)mailComposeController:(MFMailComposeViewController *)controller
      didFinishWithResult:(MFMailComposeResult)result
                    error:(NSError *)error
    {
        // save some variables here ...
        [self dismissModalViewControllerAnimated:YES]; // This line works by itself
        [self.navigationController popViewControllerAnimated:NO]; // this line causes EXC_BAD_ACCESS

然而,最后一行导致某处崩溃。 我之前和之后检查过ViewController堆栈。最后一个viewController正确地从列表中删除。

欢迎任何想法或建议。问题可能在我的代码中的其他地方,我想确保我有这个部分。谢谢。

1 个答案:

答案 0 :(得分:5)

尝试启动延迟播放

iOS 3及更高版本解决方案

-(void)mailComposeController:(MFMailComposeViewController *)controller
      didFinishWithResult:(MFMailComposeResult)result
                    error:(NSError *)error
{
    [...]
    [self dismissModalViewControllerAnimated:YES];
    [self performSelector:@selector(doThePop) withObject:nil afterDelay:0.40];
    [...]
}

- (void)doThePop
{
    [self.navigationController popViewControllerAnimated:NO];
}

您可能希望微调延迟。

iOS 5及更高版本解决方案

-(void)mailComposeController:(MFMailComposeViewController *)controller
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError *)error
{
    [...]
    [self dismissViewControllerAnimated:YES completion:^
    {
        [self.navigationController popViewControllerAnimated:NO];
    }];
    [...]
}

虽然这看起来有点像hackish,但它应该有效。