【问题标题】:How to pop to root view controller with view hierarchy containing multiple Navigation controllers如何使用包含多个导航控制器的视图层次结构弹出到根视图控制器
【发布时间】:2015-02-10 08:01:13
【问题描述】:

我有一个带有 multiple UINavigationControllers

的视图层次结构

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

我该怎么做?

我试过了

[UIApplication sharedApplication].keyWindow.rootViewController popToRootViewController];

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

请注意我想去window.rootVC。

这对我不起作用

 [self.navigationController popToRootViewControllerAnimated:YES];

【问题讨论】:

    标签: ios objective-c uiviewcontroller uinavigationcontroller


    【解决方案1】:

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

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

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      设置

      UINavigationController *navController = (UINavigationController*)self.window.rootViewController;
      
      
      [self.navigationController popToRootViewControllerAnimated:YES];
      

      【讨论】:

      • 它将进入当前导航控制器的根视图控制器......我想去window.rootviewcontroller
      猜你喜欢
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      • 2013-04-27
      • 1970-01-01
      • 2012-01-04
      相关资源
      最近更新 更多