创build第一个启动视图控制器
我试图创build一个“初始设置页面”,显示如果该应用程序是第一次在设备上启动。
我是这样做的:
- (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"); } }
现在我想创build一个视图控制器,并推送到这个视图控制器,如果这是第一次的应用程序启动。
我需要做什么?
创build一个新的ViewController。 在appDelegate.h
文件中导入头文件也要创build一个名称为initialViewController
类的实例variables。
改变你的其他条件,如:
- (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; }