• iOS基础(五)——获取当前控制器和获取当前UI控制器


    1、获取当前控制器

    -(UIViewController *)getCurrentVC{
        
        UIViewController *result = nil;
        
        UIWindow * window = [[UIApplication sharedApplication] keyWindow];
        if (window.windowLevel != UIWindowLevelNormal)
        {
            NSArray *windows = [[UIApplication sharedApplication] windows];
            for(UIWindow * tmpWin in windows)
            {
                if (tmpWin.windowLevel == UIWindowLevelNormal)
                {
                    window = tmpWin;
                    break;
                }
            }
        }
        UIView *frontView = [[window subviews] objectAtIndex:0];
        id nextResponder = [frontView nextResponder];
        
        if ([nextResponder isKindOfClass:[UIViewController class]])
            result = nextResponder;
        else
            result = window.rootViewController;
        
        return result;
    }
    

    2、获取当前UI控制器

    -(UIViewController *)getCurrentUIVC
    {
        UIViewController  *superVC = [self getCurrentVC];
        
        if ([superVC isKindOfClass:[UITabBarController class]]) {
            
            UIViewController  *tabSelectVC = ((UITabBarController*)superVC).selectedViewController;
            
            if ([tabSelectVC isKindOfClass:[UINavigationController class]]) {
                
                return ((UINavigationController*)tabSelectVC).viewControllers.lastObject;
            }
            return tabSelectVC;
        }else
            if ([superVC isKindOfClass:[UINavigationController class]]) {
                
                return ((UINavigationController*)superVC).viewControllers.lastObject;
            }
        return superVC;
    }
    
  • 相关阅读:
    Oracle的基本语法(增删改查)
    Oracle存储过程的学习
    Oracle创建联合主键
    Oracle查询当前用户的信息
    Oracle给创建函数的权限
    Oracle给存储过程权限及触发器
    Unity3D脚本的生命周期(执行顺序)
    Unity性能优化的N种武器
    序列化、反序列化(Serializable特性)
    Unity 读取资源(图片)
  • 原文地址:https://www.cnblogs.com/smileK/p/9554150.html
Copyright © 2020-2023  润新知