创建第一个启动视图控制器 [英] Creating a first launch viewcontroller

查看:97
本文介绍了创建第一个启动视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个初始设置页面,如果应用程序是第一次在设备上启动的话。

I'm trying to create a "initial setup page" that is shown if the app is launched for the first time on the device.

这个:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
    {
        NSLog(@"not first launch");
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;

    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
        [[NSUserDefaults standardUserDefaults] synchronize];



        NSLog(@"first launch");

    }
}

现在我想创建一个视图

我需要做什么?

推荐答案

创建一个新的ViewController。导入 appDelegate.h 文件中的标题还创建一个名为 initialViewController 的类的实例变量。

Create a new ViewController. Import the header in appDelegate.h file also create a instance variable of that class with name initialViewController.

更改您的else条件,如:

Change your else condition like:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
   if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
   {
       NSLog(@"not first launch");
       self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
       self.window.rootViewController = self.viewController;
   }
   else
   {
       [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
       [[NSUserDefaults standardUserDefaults] synchronize];

       self.initialViewController = [[InitialViewController alloc] initWithNibName:@"InitialViewController" bundle:nil];
       self.window.rootViewController = self.InitialViewController;
       NSLog(@"first launch");
   }
   [self.window makeKeyAndVisible];
   return YES;
}

这篇关于创建第一个启动视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆