2012-07-12 60 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的中的狀態和檢查/在應用程序加載啓動...