iOS开发之获取当前展示的VC

/** 递归查找当前显示的VC*/

+ (UIViewController *)recursiveFindCurrentShowViewControllerFromViewController:(UIViewController *)fromVC

{

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

        return [self recursiveFindCurrentShowViewControllerFromViewController:[((UINavigationController *)fromVC) visibleViewController]];

    } else if ([fromVC isKindOfClass:[UITabBarController class]]) {

        return [self recursiveFindCurrentShowViewControllerFromViewController:[((UITabBarController *)fromVC) selectedViewController]];

    } else {

        if (fromVC.presentedViewController) {

            return [self recursiveFindCurrentShowViewControllerFromViewController:fromVC.presentedViewController];

        } else {

            return fromVC;

        }

    }

}

 

/** 查找当前显示的ViewController*/

+ (UIViewController *)getCurrentShowViewController

{

    UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;

    UIViewController *currentShowVC = [self recursiveFindCurrentShowViewControllerFromViewController:rootVC];

    return currentShowVC;

}

转载于:https://www.cnblogs.com/hecanlin/p/10752964.html

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 扫一扫,分享海报

参与评论 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值