如何实现两个故事板? IOS

时间:2014-09-07 10:49:55

标签: ios storyboard xib nib

如果用户第一次打开应用程序我想要显示welocome屏幕。 如果这是我第二次要显示主屏幕。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

    if(first time)
    {
       //display welcome screen
    }

    if(second time)
    {
      //display Home screen.
    }

}

这可能是使用故事板吗? 或者我应该使用xib?

2 个答案:

答案 0 :(得分:2)

您可以使用UserDefaults保存保存状态。我不建议使用Storyboard,简单设计所有屏幕分开的笔尖。

#define kUserDefaultsHideWelcomeScreen @"welcomeScreen"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

   if(![[NSUserDefaults standardUserDefaults] boolForKey: kUserDefaultsHideWelcomeScreen]) {

     [[NSUserDefaults standardUserDefaults] setBool:YES forKey: kUserDefaultsHideWelcomeScreen];
     [[NSUserDefaults standardUserDefaults] synchronize];

     //display welcome screen
   } else {
     // display home screen
   }
}

答案 1 :(得分:0)

可以使用Storyboard和Nibs(xibs)。

这是故事板的解决方案(另外,看看UIStoryboard class):

在您的应用包中使用Welcome.storyboardHome.storyboard,这看起来像是:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

    NSString *storyboardName;
    if(first time)
    {
        storyboardName = @"Welcome";

    }
    else if(second time)
    {
        storyboardName = @"Home";
    }

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
    UIViewController *rootViewController = [mainStoryboard instantiateInitialViewController];

    // Classic window.rootViewController dance here
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    self.window.rootViewController = rootViewController;
    [self.window makeKeyAndVisible];

    return YES;
}