如何在首次推出应用时设置不同的入口点?

时间:2017-06-05 07:56:38

标签: ios storyboard

我有一个Main.storyboard包含我应用的根视图控制器。但是,我想在第一次应用启动时显示一个入职视图(没有导航控制器),以便用户只需填写一次所需的数据。所以我在考虑创建一个Onboarding.storyboard,但我不知道如何选择要设置的故事板,在哪里(AppDelegate?)以及填写数据时如何更改当前的故事板。

感谢您的帮助。

2 个答案:

答案 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;
}