獲取最上層的ViewController-IOS
阿新 • • 發佈:2018-12-17
- (UIViewController *)topViewController{ UIViewController *vc = UIApplication.sharedApplication.keyWindow.rootViewController; while ( [vc isKindOfClass:[UINavigationController class]] || [vc isKindOfClass:[UITabBarController class]] ) { if ( [vc isKindOfClass:[UINavigationController class]] ) vc = [(UINavigationController *)vc topViewController]; if ( [vc isKindOfClass:[UITabBarController class]] ) vc = [(UITabBarController *)vc selectedViewController]; if ( vc.presentedViewController ) vc = vc.presentedViewController; } return vc; }