ios - 在 iOS 中推送 View Controller 时难以绕过堆栈中的 View Controller

标签 ios uiviewcontroller uinavigationcontroller

我正在开发一个应用程序,其中依次包含三个 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/

相关文章:

ios - 我怎样才能驳回第一个 vc,第二个 vc 在第一个 vc 上以模态方式呈现

iOS:在 UI(子) View 中处理 UIGestureRecognisers

objective-c - 当我将 UINavigationController 放入 UIPopoverController 中时,navigationBar 不显示

c# - 上传前压缩 iPhone 图像

ios - 以编程方式设置文本时,不会触发 UITextField 委托(delegate)方法

Swift - 将 ViewController 插入会出现黑屏

ios - 给 UIRefreshControl 一个顶部插图

swift - 错误信息 Could not cast value type error - Swift

ios - swift 中的 Target-Action 不遵守默认参数

objective-c - UITableView - 当滚动太快时,最后一个单元格的内容会替换第一个单元格