최상위 ViewController 가져오기
+ (UIViewController*)topMostViewController { UIViewController *topMostViewController = nil; UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; if ([rootViewController isKindOfClass:[UINavigationController class]]) { UINavigationController *navigationController = (UINavigationController *)rootViewController; topMostViewController = navigationController.visibleViewController; } else if (rootViewController.presentedViewController) { topMostViewController = rootViewController.presentedViewController; } else if ([rootViewController isKindOfClass:[UITabBarController class]]) { UITabBarController *tabBarController = (UITabBarController *)rootViewController; topMostViewController = tabBarController.selectedViewController; if ([topMostViewController isKindOfClass:[UINavigationController class]]) { UINavigationController *navigationController = (UINavigationController *)topMostViewController; topMostViewController = navigationController.visibleViewController; } } else { topMostViewController = rootViewController; } return topMostViewController; }