关闭呈现的视图控制器后推送视图控制器
push view controller after dismissing presented view controller
我有这个导航堆栈
RootVC ---> VC1 -->(呈现)-> ModalVC
我有 VC2(不在导航堆栈中)。
当呈现 ModalVC 时,我想单击我的 ModalVC 中的按钮以关闭 ModalVC,然后在之后将 VC2 推入导航堆栈VC1一键。它应该是这样的:
RootVC ---> VC1 ---> VC2
我尝试了很多方法来实现它,但只有当我 return 到我的 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];
}
请帮助理解此行为。我的错误在哪里?
The presenting view controller is responsible for dismissing the view
controller it presented.
所以,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];
}];
}
其他错误。如果我理解正确的话:在关闭呈现的视图控制器之前的一些动画是导航堆栈中的阻塞动画。我用两种方法解决了这个问题:
1) 关闭前删除或设置正确的动画
2) 在导航控制器中使用setViewControllers(我select它)
- (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];
}];
}
我有这个导航堆栈
RootVC ---> VC1 -->(呈现)-> ModalVC
我有 VC2(不在导航堆栈中)。
当呈现 ModalVC 时,我想单击我的 ModalVC 中的按钮以关闭 ModalVC,然后在之后将 VC2 推入导航堆栈VC1一键。它应该是这样的:
RootVC ---> VC1 ---> VC2
我尝试了很多方法来实现它,但只有当我 return 到我的 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];
}
请帮助理解此行为。我的错误在哪里?
The presenting view controller is responsible for dismissing the view controller it presented.
所以,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];
}];
}
其他错误。如果我理解正确的话:在关闭呈现的视图控制器之前的一些动画是导航堆栈中的阻塞动画。我用两种方法解决了这个问题:
1) 关闭前删除或设置正确的动画
2) 在导航控制器中使用setViewControllers(我select它)
- (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];
}];
}