设置值,判断打开App后是进入引导页,或主页
1.在引导页中设置值
- (
void
)buttonPressed
{
MainViewController * mainVC = [[ MainViewController alloc ] init ];
[ self . navigationController pushViewController :mainVC animated : YES ];
NSUserDefaults * user = [ NSUserDefaults standardUserDefaults ];
[user setObject : @"1" forKey : @"APPFirst" ];
[user synchronize ];
MainViewController * mainVC = [[ MainViewController alloc ] init ];
[ self . navigationController pushViewController :mainVC animated : YES ];
NSUserDefaults * user = [ NSUserDefaults standardUserDefaults ];
[user setObject : @"1" forKey : @"APPFirst" ];
[user synchronize ];
}
2.在AppDelegate中做判断
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSUserDefaults * user = [NSUserDefaultsstandardUserDefaults];
if ([user objectForKey:@"APPFirst"]) {
MainViewController * mainVC = [[MainViewControlleralloc] init];
self.window.rootViewController = [[UINavigationControlleralloc] initWithRootViewController:mainVC];
}else {
GuideViewController * guideVC = [[GuideViewControlleralloc] init];
self.window.rootViewController = [[UINavigationControlleralloc] initWithRootViewController:guideVC];
}
return YES;
}