OGeek|极客世界-中国程序员成长平台

标题: iOS:从导航堆栈中删除 View Controller [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 17:10
标题: iOS:从导航堆栈中删除 View Controller

我有一个基于导航的应用程序,它需要密码才能查看某些页面。当我在 Controller A 上时,我想推送到 Passcode Controller 然后推送到 Controller B 并移除 Passcode Controller 从堆栈中。

所以要明确一点,Passcode Controller 卡在 Controller AController B 之间,我不知道如何移除它。

我尝试了两种不同的方法,但都没有给我正确的结果。

尝试 1:

ControllerB *contB = [self.storyboard instantiateViewControllerWithIdentifier"contB"];
[self.navigationController pushViewController:contB animated:YES];

[self.navigationController popViewControllerAnimated:NO];

尝试 2:

ControllerB *contB = [self.storyboard instantiateViewControllerWithIdentifier"contB"];

ControllerA *contA = [self.storyboard instantiateViewControllerWithIdentifier"contA"];

[UIView transitionFromView:contA.view
                  toView:contB.view
                  duration:0.65f
                  optionsUIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionTransitionCrossDissolve)
                  completion:^(BOOL finished){
                        self.view.window.rootViewController = contA;
                    }];

有谁知道当我从 Passcode Controller 推送 Controller B 时如何从堆栈中删除 Passcode Controller



Best Answer-推荐答案


使用 UINavigationController 上的 viewControllers 属性,如下所示:

self.navigationController.viewControllers = @[ contA, contB ];

通常,您希望在控制权传递给 Controller ​​ B 后执行此行。

这个问题还有一些其他的代码示例:Removing viewcontrollers from navigation stack

关于iOS:从导航堆栈中删除 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33764905/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4