在注销时回到初始故事板ViewController

Ven*_* D. 6 iphone ios uistoryboard uistoryboardsegue

我在iOS中使用故事板.第一个屏幕是登录屏幕.当用户注销或退出时,他可能位于深层次结构的屏幕上.

例如:login view controller => modal view controller => tab bar controller => nav controller => view controller => view controller.我想从最顶层的视图控制器一直回到底部控制器.

编辑:这是视图层次结构图:在此输入图像描述

谢谢!

Ven*_* D. 5

我为UIViewControllers编写了一个似乎正在工作的类别:

- (void) popToInitialViewController
{
    UIViewController *vc;
    if (self.navigationController != nil) {
        vc = self.navigationController;
        [self.navigationController popToRootViewControllerAnimated:NO];
        [vc popToInitialViewController];
    }
    else if (self.tabBarController != nil) {
        vc = self.tabBarController;
        [vc popToInitialViewController];
    }
    else if (self.presentingViewController != nil) {
        vc = self;

        while (vc.presentingViewController != nil)
            vc = vc.presentingViewController;

        [vc dismissModalViewControllerAnimated:NO];

        [vc popToInitialViewController];
    }
}
Run Code Online (Sandbox Code Playgroud)

评论赞赏:)


Edw*_*dar 2

假设所有内容都被推送到导航堆栈上,这应该可以工作:

[self.navigationController popToRootViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)