Skip to content

Instantly share code, notes, and snippets.

@nicolasembleton
Forked from snikch/gist:3661188
Created June 5, 2014 10:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nicolasembleton/3f430a316b07a0ae352e to your computer and use it in GitHub Desktop.
Save nicolasembleton/3f430a316b07a0ae352e 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