我有两个 Storyboard。我找到了一些关于如何实例化另一个 Storyboard 的初始 View Controller 并移动(或者你说 segue?)的代码。但是那些示例使用了导航 Controller 。在我的案例中,用户不应该能够返回到之前的 Storyboard(登录页面)。该应用程序可以忘记旧的 Storyboard,当我转移到新的 Storyboard 时不再需要它。
所以第一个 Storybard 中层次结构顶部的 View Controller 可以被遗忘,我不希望它成为下一个 Storyboard 的呈现器。它不应该存在,演示者和层次结构的顶部现在应该是第二个 Storyboard的初始 View Controller 。
我该怎么做?
最佳答案
为此,您需要:
- 实例化第二个 Storyboard
- 从第二个 Storyboard实例化所需的 View Controller
- 将窗口的 rootController 更改为新的 View Controller
这是你的做法:
//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;
}];
关于ios - 移动到另一个没有 UINavigationController 的 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22576535/