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;
  • 相关阅读:
    win10前面板耳机没声音
    学计算机的值得一看的文章,跟帖也很有水平啊
    ubuntu下编译caffe
    pip卡住不动的解决方案
    数字图像处理处理中的数学怎么提高?
    安装vmall5:从ebak恢复数据,需要配置php.ini
    python入门(7)Python程序的风格
    python入门(6)输入和输出
    python入门(5)使用文件编辑器编写代码并保存执行
    python入门(4)第一个python程序
  • 原文地址:https://www.cnblogs.com/shifu/p/5514138.html
Copyright © 2011-2022 走看看