iOS 判断当前页面

-(UIViewController*) currentViewController;

-(UIViewController*) findBestViewController:(UIViewController*)vc {

    if (vc.presentedViewController) {

        return [self findBestViewController:vc.presentedViewController];

    }else if ([vc isKindOfClass:[UISplitViewController class]]) {

        UISplitViewController* svc = (UISplitViewController*) vc;

        if (svc.viewControllers.count > 0)

            return [self findBestViewController:svc.viewControllers.lastObject];

        else

            return vc;

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

        UINavigationController * svc = (UINavigationController*) vc;

        if (svc.viewControllers.count > 0)

            return [self findBestViewController:svc.topViewController];

        else

            return vc;

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

        UITabBarController * svc = (UITabBarController*) vc;

        if (svc.viewControllers.count > 0)

            return [self findBestViewController:svc.selectedViewController];

        else

            return vc;

    }else{

        return vc;

    }

}

-(UIViewController*) currentViewController {

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

    return[self findBestViewController:viewController];

}


UIViewController* viewControllerNow = [selfcurrentViewController];

    if([viewControllerNow  isKindOfClass:[判断的页面]]) {

}

你可能感兴趣的:(iOS 判断当前页面)