标签:nav return arc result getc normal orm selected iap
+ (UIViewController *)getCurrentVC { 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; }
获取当前控制器(如果是在tabbarController中也能正确的获得当前控制器,而不是tabbarController)
标签:nav return arc result getc normal orm selected iap
原文地址:http://www.cnblogs.com/siasyl/p/6784630.html