login 跳转 到 tabbar 页面(登录界面的跳转)

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


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];

            }];

        }

}






评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值