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

启动时,初始视图是登录视图。用户成功登录后,将进入加载视图。加载数据后,我将显示拆分视图。在拆分视图上,我有一个模态显示的菜单。菜单选项包括注销。用户注销后,我想返回登录视图。到现在为止还挺好。

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

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

我正在使用情节提要和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];
                    }

                }];
            }

关于ios - ViewController层次结构-从堆栈中删除UISplitviewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28286477/

10-13 04:27