Ios 如何在第一次应用启动时设置不同的入口点?

Ios 如何在第一次应用启动时设置不同的入口点?,ios,storyboard,Ios,Storyboard,我有一个Main.storyboard,其中包含我的应用程序的根视图控制器。但是,我想在第一次应用程序启动时显示一个Onboard视图(没有导航控制器),以便用户只需填写一次数据。所以我想创建一个onboard.storyboard,但我不知道如何选择要设置的故事板,在哪里设置(AppDelegate?),以及在填充数据时如何更改当前的故事板 感谢您的帮助。您需要在AppDelegate的didFinishLaunchingWithOptions方法中更改此方法。此方法调用在每次应用程序启动期间

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


感谢您的帮助。

您需要在AppDelegate的didFinishLaunchingWithOptions方法中更改此方法。此方法调用在每次应用程序启动期间进行

方法:

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;
}
考虑这个例子。将值存储在
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;
}

对于Swift 3.x,请尝试此操作,确保在两个情节提要中都设置了初始视图控制器。在您的
AppDelegate.swift
文件中,
application:didfishlaunchwithoptions

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

哦,为什么是两个入口点。只需创建一个视图(比如IntroView)&检查应用程序的启动情况。如果用户第一次打开,则显示IntroView,否则显示nextview。这在Objective-C和Swift中的堆栈溢出问题上已被多次询问。你应该能够找到一个已经存在的问题的答案:D在使用Swift 3时,这应该是一个有用的问答:另外,对于目标C: