解除显示的视图控制器后推视图控制器 [英] push view controller after dismissing presented view controller

查看:101
本文介绍了解除显示的视图控制器后推视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个导航堆栈

RootVC ---> VC1 - >(呈现) - > ModalVC

我有 VC2 (不在导航堆栈中)。

and I have VC2 (not in navigation stack).

当呈现 ModalVC ,我想单击我的ModalVC中的按钮以关闭ModalVC,然后在 VC1 后一键将 VC2 推入导航堆栈。它应该如下所示:

When presenting ModalVC, I want to click on button in my ModalVC to dismiss ModalVC, then push VC2 into the navigation stack after VC1 at one click. It should look like this:

RootVC ---> VC1 ---> VC2

我尝试了很多方法来实现它,但是当我返回 RootVC 时,只推动事件触发。

I tried a lot of methods to make it, but pushing event fire only, when I return to my RootVC.

I试图与代表进行交流:

I tried to make it with delegates:

点击 ModalVC

[self dismissViewControllerAnimated:YES completion:^{
   if ([self.delegate respondsToSelector:@selector(dismissAndPush:)]) {
       [self.delegate performSelector:@selector(dismissAndPush:) withObject:VC2];
   }
}];

VC1

- (void)dismissAndPush:(UIViewController *)vc {
    [self.navigationController pushViewController:vc animated:NO];

}

请帮助理解此行为。我的错误在哪里?

Please help to understand this behavior. Where is my mistake?

推荐答案

错误已经出现在其他地方。如果我正确理解:在解除呈现的视图控制器之前的一些动画是阻止导航堆栈中的动画。我用两种方法解决了这个问题:

Error has been in other. If Im right understand: some animations before dismissing presented view controller are blocking animations in navigation stack. I solved this problem with 2 ways:

1)在解雇前删除或设置正确的动画

1) deleteting or set right animations before dismissing

2)使用导航控制器中的setViewControllers(我选择它)

2) use setViewControllers in navigation controller (I select it)

- (void)dismissAndPush:(UIViewController *)vc {
    [self dismissViewControllerAnimated:NO completion:^{
        NSMutableArray *mutableControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
        NSArray *controllers = [mutableControllers arrayByAddingObject:vc];
        [self.navigationController setViewControllers:controllers animated:NO];
    }];

}

这篇关于解除显示的视图控制器后推视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆