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;
  • 相关阅读:
    ajax traditional
    阿里云OSS NET SDK 引用示范程序
    js对象的两种写法
    BZOJ NOIP提高组十连测第一场
    ikbc 时光机 F87 Ctrl 失灵 解决办法
    【读书笔记】阅读的危险
    51nod 1118 机器人走方格 解题思路:动态规划 & 1119 机器人走方格 V2 解题思路:根据杨辉三角转化问题为组合数和求逆元问题
    【算法】求逆元模板
    【复习资料】软件工程之快速原型模型
    VirtualBox安装linux mint教程
  • 原文地址:https://www.cnblogs.com/shifu/p/5514138.html
Copyright © 2011-2022 走看看