【问题标题】:Move to another storyboard without a UINavigationController移动到另一个没有 UINavigationController 的故事板
【发布时间】:2014-04-29 20:52:16
【问题描述】:
我有两个故事板。我找到了一些关于如何实例化另一个 Storyboard 的初始 View Controller 并移动(或者你说 segue?)的代码。但是这些示例使用了导航控制器。在我的情况下,用户不应该能够返回到以前的故事板(登录页面)。该应用程序可以忘记旧的 Storyboard,当我转移到新的 Storyboard 时就不再需要它了。
所以第一个 Storybard 中层次结构顶部的 View Controller 可以被遗忘,我不希望它成为下一个 Storyboard 的演示者。它不应该存在,展示者和层次结构的顶部现在应该是第二个故事板的初始视图控制器。
我该怎么做?
【问题讨论】:
标签:
ios
iphone
objective-c
uinavigationcontroller
storyboard
【解决方案1】:
为此,您需要:
- 实例化第二个故事板
- 从第二个故事板实例化所需的视图控制器
- 将窗口的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;
}];