0

我正在尝试创建一个“初始设置页面”,如果应用程序首次在设备上启动,则会显示该页面。

我是这样设计的:

- (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");

    }
}

现在,如果这是第一次启动应用程序,我想创建一个视图控制器并推送到该视图控制器。

我需要做什么?

4

1 回答 1

4

创建一个新的视图控制器。导入文件中的头appDelegate.h文件还创建该类的实例变量 name initialViewController

更改您的 else 条件,例如:

- (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;
}
于 2012-12-12T08:22:02.253 回答