【问题标题】:ViewController in Navigation stack导航堆栈中的 ViewController
【发布时间】:2025-12-02 00:30:01
【问题描述】:

我在导航堆栈中有 3 个视图控制器,我都在使用它们。在删除了一些 VC 并最终呈现第三个 iOS 后,从 Navigation 堆栈中删除了第二个 VC。我需要它。如何将 VC 保存在导航堆栈中并停止删除?

我试图将它保存在应用程序委托属性中,然后弹出到它,但出现此错误:* Assertion failure in -[MenuNavigationController popToViewController:transition:], /SourceCache/UIKit_Sim/UIKit-2935.137 /UINavigationController.m:4912

        FeedViewController *vc = (FeedViewController *)[self appDelegate].feedViewController;
        [self.navigationController popToViewController:vc animated:YES];

【问题讨论】:

    标签: ios model-view-controller uiviewcontroller uinavigationcontroller navigationcontroller


    【解决方案1】:

    导航堆栈应该在其层次结构中包含您想要弹出的 vc。另外,我不太确定我明白了你的问题,你能重新措辞一下吗?

    我从您的问题中了解到,您在层次结构中有 3 个控制器 - FirstVC、SecondVc 和ThirdVC,其中 FirstVC 是第一个呈现的视图,而 thirdVC 是在连续推送视图后出现的最后一个视图,不知何故,您导航到第四个VC然后当你回到你的 ThirdVc 时,secondVC 会自动从层次结构中消失。我的理解正确吗?

    【讨论】: