移至另一个没有UINavigationController的情节提要 [英] Move to another storyboard without a UINavigationController

查看:54
本文介绍了移至另一个没有UINavigationController的情节提要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个情节提要.我找到了一些有关如何实例化另一个Storyboard的初始View Controller并将其移动(或说segue?)的代码.但是这些示例使用了导航控制器.在我的情况下(登录页面),用户不应该能够返回到先前的情节提要.该应用程序可以忘记旧的Storyboard,当我移到新的Storyboard时,就不再需要它.

I've got two storyboards. I found some code on how I can instantiate the initial View Controller of another Storyboard and move (or do you say segue?) to that. But those examples used a Navigation Controller. The user shouldn't be able to go back to the previous Storyboard in my case (login page). The app can forget about the old Storyboard, it's not needed ever again when I move over to the new one.

因此可以忘记第一个Storybard中层次结构顶部的View Controller,我不希望它成为下一个Storyboard的演示者.它不应该存在,演示者和层次结构的顶部现在应该是第二个情节提要的初始视图控制器".

So the View Controller on top of the hierarchy in the first Storybard can be forgotten about, I don't want it to be the presenter of the next Storyboard. It shouldn't exists, the presenter and top of hierarchy should now be the initial View Controller of the second Storyboard.

我该怎么做?

推荐答案

为此,您需要:

  1. 实例化第二个情节提要
  2. 从第二个情节提要板上实例化所需的视图控制器
  3. 将窗口的rootController更改为新的视图控制器

这是您的操作方式:

//Instantiate the second Storyboard
UIStoryboard *secondStoryboard = [UIStoryboard storyboardWithName:@"SecondStoryBoard" bundle:nil]; 

//Instantiate new VC, you will need to set the Storyboard Identifier of the VC to @"postLoginRoot" in your second storyboard
UIViewController *newRootVC = [secondStoryboard instantiateViewControllerWithIdentifier:@"postLoginRoot"];

//swap the root view controllers of the window
//nb: change the animation type as you see fit
UIAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UIWindow *mainWindow = delegate.window;

[mainWindow  insertSubview:newRootVC.view belowSubview:mainWindow.rootViewController.view];

[UIView transitionWithView:mainWindow
                      duration:0.8
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                        [mainWindow.rootViewController.view removeFromSuperview];
                    }
                    completion:^(BOOL completed){
                        mainWindow.rootViewController=newRootVC;
                    }];

这篇关于移至另一个没有UINavigationController的情节提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆