zoukankan      html  css  js  c++  java
  • iOS 获取当前展示的页面

    1. - (UIViewController *)getCurrentVC  
    2. {  
    3.     UIViewController *result = nil;  
    4.       
    5.     UIWindow * window = [[UIApplication sharedApplication] keyWindow];  
    6.     if (window.windowLevel != UIWindowLevelNormal)  
    7.     {  
    8.         NSArray *windows = [[UIApplication sharedApplication] windows];  
    9.         for(UIWindow * tmpWin in windows)  
    10.         {  
    11.             if (tmpWin.windowLevel == UIWindowLevelNormal)  
    12.             {  
    13.                 window = tmpWin;  
    14.                 break;  
    15.             }  
    16.         }  
    17.     }  
    18.       
    19.     UIView *frontView = [[window subviews] objectAtIndex:0];  
    20.     id nextResponder = [frontView nextResponder];  
    21.       
    22.     if ([nextResponder isKindOfClass:[UIViewController class]])  
    23.         result = nextResponder;  
    24.     else  
    25.         result = window.rootViewController;  
    26.       
    27.     return result;  
    28. }  

     
    1. - (UIViewController *)getPresentedViewController  
    2. {  
    3.     UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;  
    4.     UIViewController *topVC = appRootVC;  
    5.     if (topVC.presentedViewController) {  
    6.         topVC = topVC.presentedViewController;  
    7.     }  
    8.       
    9.     return topVC;  
    10. }  
    11. 如果是在AppDelegate中
    12. 如果是用UINavigationController来组织页面结构的话可以使用:

      ((UINavigationController*)appDelegate.window.rootViewController).visibleViewController;

      如果是用UITabBarController来组织页面结构的话:

      ((UITabBarController*)appDelegate.window.rootViewController).selectedViewController;
  • 相关阅读:
    数据挖掘-基本流程
    ArcGIS GP应用-GP模型服务发布
    ArcGIS GP应用-GP模型创建-缓冲区分析
    Hadoop2的Yarn和MapReduce2相关
    hadoop学习WordCount+Block+Split+Shuffle+Map+Reduce技术详解
    WordCount示例深度学习MapReduce过程
    数组的几种排序算法的实现
    hBase官方文档以及HBase基础操作封装类
    Hive SQL执行流程分析
    Hive SQL的编译过程
  • 原文地址:https://www.cnblogs.com/shifu/p/5514138.html
Copyright © 2011-2022 走看看