在我的应用程序中,我有一个ViewController加载为欢迎屏幕。点击“开始”,然后出现另一个ViewController,让用户创建一个帐户。提交信息时,会显示其个人资料。 (这是一个有趣的测试应用程序)我想这样做,以便当用户注册,使用他们的配置文件然后退出应用程序,他们不必继续重新注册。所以我需要帮助检测首次启动的应用程序,然后使WelcomeViewController和RegisterViewController在首次启动后消失。
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 :(得分:0)
您正在寻找NSUserDefaults ...在NSUserDefaults中存储登录用户的状态,并在应用程序启动时检查/加载它...