ViewController 层次结构 - 从堆栈中删除 UISplitviewController

ViewController Hierarchy - Remove UISplitviewController from stack

我的应用有登录视图、加载视图、拆分视图和菜单视图。

启动时,初始视图是登录视图。当用户成功登录时,它会进入加载视图。加载数据后,我会显示拆分视图。在拆分视图中,我有一个模态显示的菜单。菜单的选项之一是注销。当用户注销时,我想 return 到登录视图。到目前为止,还不错。

问题是当我检查视图层次结构时,拆分视图仍在登录视图下方。理论上,用户可以通过这种方式创建一个具有无限多个分层视图的情况。

如何让用户返回登录视图并关闭拆分视图?

我正在使用故事板和 segues 来获得拆分视图。登录视图推送到加载视图,加载视图推送到拆分视图。我在自定义模态呈现控制器中呈现模态菜单。

            //VC1


            -(IBAction)button_click:(id)sender
            {
                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                ViewController2 *viewController2 = [storyboard instantiateViewControllerWithIdentifier:@"VC2"];

                [self.navigationController pushViewController:viewController2 animated:YES];
            }


            //VC2


            -(IBAction)button_click:(id)sender
            {

                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                ViewController3 *viewController3 = [storyboard instantiateViewControllerWithIdentifier:@"VC3"];

                [self.navigationController pushViewController:viewController3 animated:YES];

            }

            //VC3
    // In .h file
    @interface ViewController3 : UIViewController<ViewController4Delegate>

    -(IBAction)button_click:(id)sender;

    @end

         //In .m file   
            -(IBAction)button_click:(id)sender
            {
                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                ViewController4 *viewController4 = [storyboard instantiateViewControllerWithIdentifier:@"VC4"];

                viewController4.delegate=self;

                [self.navigationController presentViewController:viewController4 animated:YES completion:nil];
            }

            -(void)completed
            {
                [self.navigationController popToRootViewControllerAnimated:YES];
[self.parentViewController.parentViewController dismissViewControllerAnimated:YES completion:nil];
            }

            //VC4
            //In .h file
            @protocol  ViewController4Delegate

        -(void)completed;

        @end

        @interface ViewController4 : UIViewController

        -(IBAction)button_click:(id)sender;

        @property(nonatomic,weak) id <ViewController4Delegate> delegate

         //In.m file
            -(IBAction)button_click:(id)sender
            {


                [self dismissViewControllerAnimated:NO completion:^{

                    if(delegate)
                    {
                        [delegate completed];
                    }

                }];
            }

你有这个 ViewController 层次结构的导航控制器吗?假设你有一个导航控制器:

如果将 LoginView 设置为导航控制器的根 ViewController 并且 LoadingView 和 SplitView "pushed" 到导航堆栈,那么您可以做的是关闭模态和在完成块中,您可以弹出到根视图控制器 -> 这将是您的登录控制器。

所以在您的 LogoutModal 中,您将在注销按钮单击处理程序上执行此操作:

[self.presentingViewController dismissViewControllerAnimated:YES completion:^{
    [self.presentingViewController.navigationController popToRootViewControllerAnimated:YES];
}];

这会关闭模态,然后一旦完成,它就会将导航堆栈弹出,一直返回到根视图控制器。