我有一个Main.storyboard
包含我应用的根视图控制器。但是,我想在第一次应用启动时显示一个入职视图(没有导航控制器),以便用户只需填写一次所需的数据。所以我在考虑创建一个Onboarding.storyboard
,但我不知道如何选择要设置的故事板,在哪里(AppDelegate
?)以及填写数据时如何更改当前的故事板。
感谢您的帮助。
答案 0 :(得分:4)
尝试使用Swift 3.x,确保在两个故事板中设置初始视图控制器。在AppDelegate.swift
文件中,application:didFinishLaunchingWithOptions
var storyboardName:String?
if someCondition {
storyboardName = "Onboarding"
}else{
storyboardName = "Main"
}
let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
let intialVC = storyboard.instantiateInitialViewController()
self.window?.rootViewController = intialVC
答案 1 :(得分:1)
您需要在AppDelegate的didFinishLaunchingWithOptions方法中更改此方法。每次在应用启动期间调用此方法。
如何强>
考虑这个例子。将值存储在NSUserdefaults
中,并在应用启动期间检索它。
示例强>
目标C:
BOOL isCompletedSetupWizard =[[NSUserDefaults standardUserDefaults] boolForKey:@"isCompletedSetupWizard"];
if (isCompletedSetupWizard)
{
//Your code goes here
//....
//....
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
viewController = [storyboard instantiateViewControllerWithIdentifier:@"yourFirstView"];
self.window.rootViewController = viewController;
}
else
{
//Your code goes here for another view controller.
//....
//....
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"onBoarding" bundle:nil];
viewController = [storyboard instantiateViewControllerWithIdentifier:@"yourSecondView"];
self.window.rootViewController = viewController;
}