presentViewController和pushViewController跳转页面之后,如何回到最初的页面?

A页面跳到B页面。用模态切换presentViewController的方式跳转

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:VC];
    [self presentViewController:nav animated:YES completion:nil];

这样跳到了B页面。B又跳到了C页面。C又跳到D页面。

用导航控制器入栈的方式切换,代码如下:

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

现在问题来了。我要从D页面。直接回到A页面。应该怎么回?


好像这样解决了

[((UIViewController*)weakSelf.navigationController.viewControllers[0]) dismissViewControllerAnimated:YES completion:^{
                    [[NSNotificationCenter defaultCenter] postNotificationName:NotificationLoginCallBack object:nil];
                }];

只是还不算完美。首先切到了B页面,然后B消失,回到了A页面。
如果能从D直接动画切到A。不经过B页面,更完美。不过目前算可用了
希望有更完美的方案

阅读 13k
3 个回答

昨天没时间就占位随便答了一下,今天我测试了一下后,结论是:

直接调用 self.navigationController 的 dismissViewControllerAnimated 方法。
动画效果就是直接的向下推出。

for (UIViewController *temp in self.navigationController.viewControllers) {

    if ([temp isKindOfClass:[AviewController class]]) {
        [self.navigationController popToViewController:temp animated:YES];
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题