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

时间:2015-02-02 20:49:30

标签: ios objective-c iphone uiviewcontroller uisplitviewcontroller

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

view flow

启动时,初始视图是登录视图。当用户成功登录时,它将进入加载视图。加载数据后,我会显示拆分视图。在拆分视图中,我有一个菜单,我以模态方式呈现。该菜单的选项包括注销。当用户注销时,我想返回登录视图。到目前为止,非常好。

问题在于,当我检查视图层次结构时,拆分视图仍在登录视图下方。从理论上讲,用户可以通过这种方式创建具有无限数量分层视图的情境。

stacked views

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

我正在使用故事板和segues进入拆分视图。登录视图将推送到加载视图,该视图将推送到拆分视图。我在自定义模式演示控制器中显示模态菜单。

2 个答案:

答案 0 :(得分:1)

            //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];
                    }

                }];
            }

答案 1 :(得分:0)

您是否有此ViewController层次结构的导航控制器?假设你有一个导航控制器:

如果将LoginView设置为导航控制器的rootViewController,并将LoadingView和SplitView“推”到导航堆栈上,那么你可以做的是你可以解除模态并在完成块中,你可以弹出到根视图控制器 - &gt;这将是你的登录控制器。

因此,在LogoutModal中,您可以在Logout按钮上单击Handler:

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

这解散了模态,然后一旦完成,就会将导航堆栈一直弹回到根视图控制器。