美文网首页
oc获取控制器跳转

oc获取控制器跳转

作者: 有理想有暴富的小青年 | 来源:发表于2020-08-24 10:47 被阅读0次

    -(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获取控制器跳转

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