ios - 移动到另一个没有 UINavigationController 的 Storyboard

标签 ios iphone objective-c uinavigationcontroller storyboard

我有两个 Storyboard。我找到了一些关于如何实例化另一个 Storyboard 的初始 View Controller 并移动(或者你说 segue?)的代码。但是那些示例使用了导航 Controller 。在我的案例中,用户不应该能够返回到之前的 Storyboard(登录页面)。该应用程序可以忘记旧的 Storyboard,当我转移到新的 Storyboard 时不再需要它。

所以第一个 Storybard 中层次结构顶部的 View Controller 可以被遗忘,我不希望它成为下一个 Storyboard 的呈现器。它不应该存在,演示者和层次结构的顶部现在应该是第二个 Storyboard的初始 View Controller 。

我该怎么做?

最佳答案

为此,您需要:

  1. 实例化第二个 Storyboard
  2. 从第二个 Storyboard实例化所需的 View Controller
  3. 将窗口的 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/

相关文章:

iphone - 问题 pushViewController 从 Landscape 到 Portrait

iphone - Facebook Connect 发布状态更新

iphone - 调用 CocoaAsyncMethod scheduleDequeueRead 时应用程序卡住

ios - FBAnnotationClustering 以编程方式显示注释

ios - 使用 AFNetworking 显示下载图像的进度

ios - UI 测试 - 如何检查我是否在正确的 Controller 中?

ios - pubnub显示消息“无法保存转储”是错误吗?如果没有,如何将其静音?

ios - 我怎样才能让背景不覆盖每个按钮、标签?

iphone - 如何从 ABAddressBook 中快速获取组成员计数

iphone - 如何从 NSData 读取字节