oc获取控制器跳转

-(UIViewController *)sn_getCurrentVC{

    UIWindow* window = [[[UIApplication sharedApplication] delegate] window];

    UIViewController* currentViewController = window.rootViewController;

    BOOLrunLoopFind =YES;

    while(runLoopFind) {

        if(currentViewController.presentedViewController) {

            currentViewController = currentViewController.presentedViewController;

        }elseif([currentViewControllerisKindOfClass:[UINavigationControllerclass]]) {

            UINavigationController* navigationController = (UINavigationController* )currentViewController;

            currentViewController = [navigationController.childViewControllerslastObject];

        }elseif([currentViewControllerisKindOfClass:[UITabBarControllerclass]]) {

            UITabBarController* tabBarController = (UITabBarController* )currentViewController;

            currentViewController = tabBarController.selectedViewController;

        }else{

            NSUIntegerchildViewControllerCount = currentViewController.childViewControllers.count;

            if(childViewControllerCount >0) {

                currentViewController = currentViewController.childViewControllers.lastObject;

                returncurrentViewController;

            }else{

                returncurrentViewController;

            }

        }

    }

    returncurrentViewController;

}

你可能感兴趣的:(oc获取控制器跳转)