我正在开发一个应用程序,其中依次包含三个 View Controller :ViewControllerA、ViewControllerB 和 ViewControllerC。在某些情况下,我需要用户从 ViewControllerA 直接转到 ViewControllerC,但不幸的是,在转换到 ViewControllerC 的过程中,ViewControllerB 会短暂出现在屏幕上,这是我不希望看到的。
这是我正在使用的代码:
VCA 内部:
ViewControllerB *vcB = [ViewControllerB new];
ViewControllerC *vcC = [ViewControllerC new];
vcB.rootViewController = self;
[self.navigationController pushViewController:vcB animated:NO];
[self.navigationController pushViewController:vcC animated:YES];
正如我上面提到的,上面的代码发生在 ViewControllerA 内部,我能够到达 ViewControllerC,问题是不幸的是,ViewControllerB 在转换过程中暂时显示。我做错了什么,我需要做什么来解决这个问题?
最佳答案
简单。这是一些几乎正确的伪代码
NSMutableArray *vcStack = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[vcStack addObject:vcB];
[vcStack addObject:vcC];
[self.navigationController setViewControllers:vcStack animated:YES];
显然,如果您不想要现有的 View 堆栈,您可以将其丢弃并制作您自己的数组,但是这可能会导致动画出现故障。
查看 UINavigationController 的文档以获取更多信息: https://developer.apple.com/library/ios/documentation/Uikit/reference/UINavigationController_Class/index.html#//apple_ref/occ/instm/UINavigationController/setViewControllers:animated :
关于ios - 在 iOS 中推送 View Controller 时难以绕过堆栈中的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26765947/