项目有点紧张,好久没有写点东西了。后面我会抽更多时间学习和分享学习的一些总结,分享给各位,请持续关注。
具体场景我都不说了。直接上代码
- (void)needShowLogin
{
YPJGLoginViewController * login = [[YPJGLoginViewController alloc] init];
login.hidesBottomBarWhenPushed = YES;
UIViewController * VC = [self currentViewController];
YPJGLog(@"当前显示的控制器%@",VC);
//判断是否已经显示登录窗口,没有显示则push显示
if (![[NSString stringWithUTF8String:object_getClassName(VC)] isEqual:[NSString stringWithUTF8String:object_getClassName(login)]])
{
[VC.navigationController pushViewController:login animated:YES];
}
}
//获取Window当前显示的ViewController
- (UIViewController*)currentViewController{
//获得当前活动窗口的根视图
UIViewController* vc = [UIApplication sharedApplication].keyWindow.rootViewController;
while (1)
{
//根据不同的页面切换方式,逐步取得最上层的viewController
if ([vc isKindOfClass:[UITabBarController class]