美文网首页
获取当前最顶层的VC

获取当前最顶层的VC

作者: 奋斗吧程序员 | 来源:发表于2019-04-27 10:11 被阅读0次

#pragma mark -  获取当前最顶层的ViewController

- (UIViewController*)topVC:(UIViewController*)VC {

    if([VC isKindOfClass:[UINavigationControllerclass]]) {

        return[selftopVC:[(UINavigationController*)VC topViewController]];

    }

    if([VC isKindOfClass:[UITabBarControllerclass]]) {

        return[selftopVC:[(UITabBarController*)VC selectedViewController]];

    }

    returnVC;

}

- (UIViewController*)topViewController {

    UIViewController*vc = [selftopVC:[UIApplicationsharedApplication].keyWindow.rootViewController];

    while(vc.presentedViewController) {

        vc = [selftopVC:vc];

    }

    returnvc;

}

相关文章

网友评论

      本文标题:获取当前最顶层的VC

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