获取当前控制器

2017-09-14  本文已影响6人  Moker_C

- (UIViewController *)presentingVC{

UIWindow * window = [[UIApplication sharedApplication] keyWindow];

if (window.windowLevel != UIWindowLevelNormal){

NSArray *windows = [[UIApplication sharedApplication] windows];

for(UIWindow * tmpWin in windows){

if (tmpWin.windowLevel == UIWindowLevelNormal){

window = tmpWin;

break;

}

}

}

UIViewController *result = window.rootViewController;

while (result.presentedViewController) {

result = result.presentedViewController;

}

if ([result isKindOfClass:[UITabBarController class]]) {

result = [(UITabBarController *)result selectedViewController];

}

if ([result isKindOfClass:[UINavigationController class]]) {

result = [(UINavigationController *)result topViewController];

}

return result;

}

上一篇下一篇

猜你喜欢

热点阅读