1.我是放弃使用
[self presentViewController:[MainTabBarController new] animated:YES completion:nil];
2.登录时候在登录成功的方法里面写(第一次变根)
[[[UIApplication sharedApplication].delegate window].rootViewController removeFromParentViewController];
MainTabBarController *mvc = [[MainTabBarController alloc]init];
[[UIApplication sharedApplication].delegate window].rootViewController = mvc;
[[[UIApplication sharedApplication].delegate window] makeKeyAndVisible];
3.在退出登录的方法里面写(第二次变根)
//还就是清除数据缓存
[[[UIApplication sharedApplication].delegate window].rootViewController removeFromParentViewController];
LoginPageViewController *vc = [[LoginPageViewController alloc]init];
UINavigationController *lgNC = [[UINavigationController alloc]initWithRootViewController:vc];
[[UIApplication sharedApplication].delegate window].rootViewController = lgNC;
[[[UIApplication sharedApplication].delegate window] makeKeyAndVisible];
4.在跟试图(登录什么的页面都继承于BaseViewController中)(目的是方便监控踢出事件)(踢出到登陆界面在token过期http请求时候监控)
在BaseViewController相应方法中写踢出事件
(1.) [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(goBackToLogin:)
name:GO_BACK_TO_LOGIN_VC
object:nil];
(2.)
-(void)goBackToLogin:(NSNotification *)notification{
dispatch_async(dispatch_get_main_queue(), ^{
if([notification.name isEqualToString:GO_BACK_TO_LOGIN_VC]){
//还就是清除数据缓存
[[[UIApplication sharedApplication].delegate window].rootViewController removeFromParentViewController];
LoginPageViewController *vc = [[LoginPageViewController alloc]init];
UINavigationController *lgNC = [[UINavigationController alloc]initWithRootViewController:vc];
[[UIApplication sharedApplication].delegate window].rootViewController = lgNC;
[[[UIApplication sharedApplication].delegate window] makeKeyAndVisible];
}];
}
}

本文介绍了在iOS应用中如何实现从登录界面平滑地跳转到TabBar页面,包括登录成功后的首次设置TabBar为根视图,退出登录时返回登录界面,以及在BaseViewController中监听并处理踢出登录事件的方法。详细步骤包括使用presentViewController、更换rootViewController以及处理通知事件。
724

被折叠的 条评论
为什么被折叠?



