如何使用包含多个导航控制器的视图层次结构弹出到根视图控制器 [英] How to pop to root view controller with view hierarchy containing multiple Navigation controllers

查看:17
本文介绍了如何使用包含多个导航控制器的视图层次结构弹出到根视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 多个 UINavigationControllers

现在从一个特定的视图控制器,我想弹出到 window.rootviewcontroller

Now from a particular view controller, I wanted to pop to window.rootviewcontroller

我该怎么做?

我试过了

[UIApplication sharedApplication].keyWindow.rootViewController popToRootViewController];

[UIApplication sharedApplication].keyWindow.rootViewController popToRootViewController];

但它不起作用.请提出建议.

But it does not work. Please suggest.

请注意,我想转到 window.rootVC.

Please note I want to go to window.rootVC.

这对我不起作用

 [self.navigationController popToRootViewControllerAnimated:YES];

推荐答案

只需获取窗口实例并再次设置根视图控制器,因为 popToRootViewController 只会弹出特定导航堆栈的根视图控制器

Just get the window instance and set the root view controller again, as popToRootViewController only pops to root view controller of particular navigation stack

- (void)popToRoot
{
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    UIWindow *mainWindow = appDelegate.window;
    ViewController *viewControllerObj = [ViewController new];
    UINavigationController *navigationObject = [[UINavigationController alloc] initWithRootViewController:viewControllerObj];
    [mainWindow setRootViewController:navigationObject];
}

希望这会有所帮助.

这篇关于如何使用包含多个导航控制器的视图层次结构弹出到根视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆