-
(UIViewController *)getCurrentVC{
UIViewController *currVC = nil;
UIViewController *rootvc = self.window.rootViewController;
do {
if ([rootvc isKindOfClass:[UINavigationController class]]) {//控制器为UINavigationController
UINavigationController *nav = (UINavigationController *)rootvc;
UIViewController *vc = [nav.viewControllers lastObject];
currVC = vc;
rootvc = vc.presentedViewController;}else if ([rootvc isKindOfClass:[UITabBarController class]]){//控制器为UITabBarController UITabBarController *tabVC = (UITabBarController *)rootvc; currVC = tabVC ; rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex]; continue; }else {//控制器为UIViewController UIViewController *VC = (UIViewController *)rootvc; currVC = VC; rootvc = VC.presentedViewController; }
} while (rootvc != nil);
return currVC;
}
网友评论