切换的首要领
- - (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;
- }
(编辑:河北网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|