关闭呈现的视图控制器后推送视图控制器 [英] push view controller after dismissing presented view controller
问题描述
我有这个导航栈
RootVC ---> VC1 --> (presenting)-> 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.
我试着和代表一起做:
在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.如果我理解正确:在关闭呈现的视图控制器之前的一些动画会阻塞导航堆栈中的动画.我用两种方法解决了这个问题:
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屋!