有没有办法将视图控制器推送到导航控制器而不进行堆叠?
通缉行为(堆叠表示):
[VC1 [VC2]] - >从VC2推送VC3 - > [VC1 [VC3]]
答案 0 :(得分:6)
是的,只是弹出另一个(没有动画这个),就像这样:
[navController popViewControllerAnimated:NO]
[navController pushViewController:VC3 animated:YES]
或者选择选项2,这更通用:替换viewControllers属性:
NSArray *newControllers = @[VC1, VC3];
[navController setViewControllers:newControllers animated:YES];
...或
NSArray *newControllers = @[navController.viewControllers[0], VC3];
[navController setViewControllers:newControllers animated:YES];
答案 1 :(得分:1)
我会使用UINavigationController的方法:
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
这样你可以这样做:
UINavigationController *navigationController = [self navigationController];
[navigationController setViewControllers:@[navigationController.viewControllers[0], VC3] animated:YES];
这将为您提供新视图控制器(VC3)的推送动画。