美文网首页
获取当前viewcontroller

获取当前viewcontroller

作者: 凄美的月光 | 来源:发表于2017-05-11 15:10 被阅读0次

    //获取当前屏幕显示的viewcontroller

    - (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {

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

    UITabBarController* tabBarController = (UITabBarController*)rootViewController;

    return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];

    } else if ([rootViewController isKindOfClass:[UINavigationController class]]) {

    UINavigationController* navigationController = (UINavigationController*)rootViewController;

    return [self topViewControllerWithRootViewController:navigationController.visibleViewController];

    } else if (rootViewController.presentedViewController) {

    UIViewController* presentedViewController = rootViewController.presentedViewController;

    return [self topViewControllerWithRootViewController:presentedViewController];

    }

    else {

    return rootViewController;

    }

    }

    相关文章

      网友评论

          本文标题:获取当前viewcontroller

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