| 切换的主方法 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 1. 注册登录成功的通知观察者 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:@"loginSuccess" object:nil]; // 2. 注册登录成功的通知观察者 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccess) name:@"logoutSuccess" object:nil]; // 每次app打开后,应该展示给用户哪个界面 // 3. 利用偏好设置中用户保存的信息来判断用户的登录状态 NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:kUserNameKey]; NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:kPasswordKey]; if (userName && password) { // 显示app 主界面 [self loginSuccess]; } else { [self logoutSuccess]; } return YES; } 
 登录成功 - (void)loginSuccess { NSLog(@"登录成功!"); // 获取主界面 UIStoryboard *mainSb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; // 切换控制器 self.window.rootViewController = mainSb.instantiateInitialViewController; } 
 注销成功 - (void)logoutSuccess { NSLog(@"注销成功!"); // 获取登录界面 UIStoryboard *loginSb = [UIStoryboard storyboardWithName:@"Login" bundle:nil]; // 切换控制器 self.window.rootViewController = loginSb.instantiateInitialViewController; } 
 (编辑:宣城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |