Skip to content

Instantly share code, notes, and snippets.

@mane-sandeep
Forked from snikch/gist:3661188
Created August 23, 2014 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mane-sandeep/bee030af4d1596f9ea46 to your computer and use it in GitHub Desktop.
Save mane-sandeep/bee030af4d1596f9ea46 to your computer and use it in GitHub Desktop.
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
if ([rootViewController.presentedViewController isMemberOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
return [self topViewController:lastViewController];
}
UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
return [self topViewController:presentedViewController];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment