zoukankan      html  css  js  c++  java
  • 获取当前的 viewController

    - (UIViewController *)currentController {
        UIViewController *result = nil;
        UIWindow *window = [[UIApplication sharedApplication] keyWindow];
        
        if (window.windowLevel != UIWindowLevelNormal) {
            NSArray *windows = [[UIApplication sharedApplication] windows];
            
            for (UIWindow *temWin in windows) {
                if (temWin.windowLevel == UIWindowLevelNormal) {
                    window = temWin;
                    break;
                }
            }
        }
        
        UIView *frontView = [[window subviews] objectAtIndex:0];
        id nestResponder = [frontView nextResponder];
        if ([nestResponder isKindOfClass:[UIViewController class]]) {
            result = nestResponder;
        } else {
            result = window.rootViewController;
        }
        return result;
    }

  • 相关阅读:
    LeetCode 43 字符串相乘
    HDU 1031 Design T-Shirt
    HDU 1728 逃离迷宫
    HDU 1285 确定比赛名次
    HDU 1116 Plays on words
    HDU 1195 Open the lock
    HDU 1072 Nightmare
    HDU 1272 小希的迷宫
    HDU 1273 漫步森林
    HDU 1269 迷宫城堡
  • 原文地址:https://www.cnblogs.com/rollrock/p/5630929.html
Copyright © 2011-2022 走看看