zoukankan      html  css  js  c++  java
  • Appdelegate 跳转其他页面 获取当前屏幕显示的viewcontroller 获取当前屏幕中present出来的viewcontroller 获取当前导航控制器

    Appdelegate 跳转其他页面

    UITabBarController *tab = (UITabBarController *)_window.rootViewController;    

    UINavigationController *nav = tab.viewControllers[tab.selectedIndex];    

    MessageViewController *vc = [[MessageViewController alloc] init];    需要跳转的页面

    vc.hidesBottomBarWhenPushed = YES;    

    [nav pushViewController:vc animated:YES]; 

     

     

    //获取当前屏幕显示的viewcontroller

    - (UIViewController *)getCurrentVC{

        UIWindow *window = [[UIApplication sharedApplication].windows firstObject];

        if (!window) {

            return nil;

        }

        UIView *tempView;

        for (UIView *subview in window.subviews) {

            if ([[subview.classForCoder description] isEqualToString:@"UILayoutContainerView"]) {

                tempView = subview;

                break;

            }

        }

        if (!tempView) {

            tempView = [window.subviews lastObject];

        }

        

        id nextResponder = [tempView nextResponder];

        while (![nextResponder isKindOfClass:[UIViewController class]] || [nextResponder isKindOfClass:[UINavigationController class]] || [nextResponder isKindOfClass:[UITabBarController class]]) {

            tempView =  [tempView.subviews firstObject];

            

            if (!tempView) {

                return nil;

            }

            nextResponder = [tempView nextResponder];

        }

        return  (UIViewController *)nextResponder;

    }

    //获取当前屏幕中present出来的viewcontroller。

    - (UIViewController *)getPresentedViewController

    {

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

        UIViewController *topVC = appRootVC;

        if (topVC.presentedViewController) {

            topVC = topVC.presentedViewController;

        }

        return topVC;

    }

    // 获取当前导航控制器

    - (BaseNavigationController *)getNavController{

        BaseTableBarControllerView *tabVC = (BaseTableBarControllerView *)self.window.rootViewController;

        tabVC.selectedIndex = 2;

        BaseNavigationController *pushClassStance = (BaseNavigationController *)tabVC.selectedViewController;

        return pushClassStance;

    }

  • 相关阅读:
    Django框架之第三篇模板语法
    Django框架之第二篇
    Django框架第一篇基础
    【数学基础】【快速幂运算模板】
    【搜索】【广搜模板】
    【动态规划】【子序列模板】
    [置顶] 【ACM模板】——hello_chengdongni 随着姿势提升,不定期补充
    【搜索入门专题1】 hdu1242 J
    【搜索入门专题1】E
    【搜索入门专题1】hdu1253 【BFS】 F
  • 原文地址:https://www.cnblogs.com/liaolijun/p/8304133.html
Copyright © 2011-2022 走看看