2012-07-12 76 views
1

在我的应用程序中,我有一个ViewController作为欢迎屏幕加载。您点击“开始”,然后ViewController出现,使用户创建一个帐户。当提交信息时,他们的个人资料出现。 (这是一个有趣的测试应用程序)我想这样做,当用户注册,使用他们的个人资料然后退出应用程序,他们不必重新注册。所以我需要帮助检测应用程序首次启动,然后使WelcomeViewController和RegisterViewController首次启动后消失。第一次启动后隐藏ViewControllers

WelcomeViewController:

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

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"hasLaunchedOnce"]) { 

    ProfileViewController *profileVC = [[ProfileViewController alloc] initWithNibName:nil bundle:nil]; 

    [self presentViewController:profileVC animated:NO completion:nil]; 

} else { 

    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasLaunchedOnce"]; 

    [[NSUserDefaults standardUserDefaults] synchronize]; 

    } 
} 

RegisterViewController:

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

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"hasLaunchedOnce"]) { 

    ProfileViewController *profileVC = [[ProfileViewController alloc] initWithNibName:nil bundle:nil]; 

    [self presentViewController:profileVC animated:NO completion:nil]; 

} else { 

    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasLaunchedOnce"]; 

    [[NSUserDefaults standardUserDefaults] synchronize]; 

    } 
} 
+0

你不应该检查它的应用程序的第一次启动。如果用户实际创建了帐户,则应该存储在NSUserDefaults中。他可能会启动您的应用程序,但仍未注册。 – tomidelucca 2012-07-12 09:08:23

回答

0

是NSUserDefaults的你在找什么......存储的登录用户NSUserDefaults的中的状态和检查/在应用程序加载启动...