ios - 弹出到 Root View Controller 问题

标签 ios iphone uinavigationcontroller

在我的项目中,我在导航 Controller 中添加了一些 View Controller 。

UIViewController1,UIViewController2,UIViewController3,UIViewController4,UIViewController5 考虑 UIViewController1 是我的导航 Controller 的 Root View Controller 。在单击按钮导航到达 UIViewContoller5 后,我需要返回到我的 UIViewController1。所以我正在编写以下代码。

 - (void)popToRootViewControllerAnimated
    {
        NSLog(@"%@",[self.navigationController viewControllers]);
        [self.navigationController popToRootViewControllerAnimated:NO];
    }

在控制台中打印如下

(
    "<UIViewController1: 0x8e3fcc0>",
    "<UIViewController2: 0x9a5d310>",
    "<UIViewController3: 0x9a67b00>",
    "<UIViewController4: 0x9162a00>",
    "<UIViewController5: 0x9a84380>"
)

但在它完成执行后,我的 View 停留在 UIViewController3。如果我在我的 UIViewController3 中打印 [self.navigationController viewControllers] 它显示为,

(
        "<UIViewController1: 0x8e3fcc0>",
        "<UIViewController3: 0x9a67b00>",
    )

我错过了什么。提前致谢。任何帮助,将不胜感激。

最佳答案

试试这个:

UIViewController *firstVc = [viewControllers objectAtIndex:0];
[navCtrl setViewControllers:@[firstVc] animated:NO];

关于ios - 弹出到 Root View Controller 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21878527/

相关文章:

ios - 如何使用 getObjectInBackgroundWithId 和 saveInBackgroundWithBlock 从 Parse 检索数据

ios - React Native 与 Appsee 中的触摸手势问题

iphone - iPhone 中带有进度条和取消按钮的启动屏幕

ios - UINavigationController 包含、iOS7 和状态栏。漏洞?

ios - 更改 UISplitViewController iOS 8 中的详细导航项

Xcode 表格 View 隐藏在导航栏后面

ios - 几次滚动后 CollectionView 在 NSISEngine 中崩溃

ios - AppDelegate : call function only if theres a new notification, 怎么办?

android - 打开与电话无关的应用程序的短信链接?

iphone - 将图像保存到 iPhone 时出错