美文网首页
获取当前控制器

获取当前控制器

作者: Moker_C | 来源:发表于2017-09-14 17:49 被阅读6次

    - (UIViewController *)presentingVC{

    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;

    }

    }

    }

    UIViewController *result = window.rootViewController;

    while (result.presentedViewController) {

    result = result.presentedViewController;

    }

    if ([result isKindOfClass:[UITabBarController class]]) {

    result = [(UITabBarController *)result selectedViewController];

    }

    if ([result isKindOfClass:[UINavigationController class]]) {

    result = [(UINavigationController *)result topViewController];

    }

    return result;

    }

    相关文章

      网友评论

          本文标题:获取当前控制器

          本文链接:https://www.haomeiwen.com/subject/cendsxtx.html