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;

    }

  • 相关阅读:
    hasCode in Java
    如何区分同一Class的不同实例对象
    如何构建XML文件
    Spring <context:property-placeholder/>的作用
    关于List的几个方法
    Java 中那些不常用的关键字
    设计模式
    Java源代码阅读-Object.toString()
    修复启动项
    centos关闭防火前
  • 原文地址:https://www.cnblogs.com/liaolijun/p/8304133.html
Copyright © 2011-2022 走看看