获取当前最顶层的VC

#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)