我有这个导航堆栈
RootVC ---> VC1 - > (呈递) - > ModalVC
我有 VC2 (不在导航堆栈中)。
在展示 ModalVC 时,我想点击我的ModalVC中的按钮以关闭ModalVC,然后在 VC1 之后将 VC2 推入导航堆栈只需点击一下。它应该是这样的:
RootVC ---> VC1 ---> VC2
我尝试了很多方法来实现它,但是当我返回 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];
}
请帮助理解这种行为。我的错误在哪里?
答案 0 :(得分:1)
其他地方出现了错误。如果我正确理解:在解除呈现的视图控制器之前的一些动画是阻止导航堆栈中的动画。我用两种方法解决了这个问题:
1)在解雇之前删除或设置正确的动画
2)在导航控制器中使用setViewControllers(我选择它)
- (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];
}];
}
答案 1 :(得分:0)
呈现视图控制器负责解除视图 它呈现的控制器。
所以,VC1应该解雇ModalVC,尝试这样做
点击时的ModalVC:
if ([self.delegate respondsToSelector:@selector(dismissAndPush:)]) {
[self.delegate performSelector:@selector(dismissAndPush:) withObject:VC2];
}
在VC1中:
- (void)dismissAndPush:(UIViewController *)vc {
[self dismissViewControllerAnimated:YES completion:^{
[self.navigationController pushViewController:vc animated:NO];
}];
}