Skip to content

Instantly share code, notes, and snippets.

@dzenbot
Last active April 24, 2018 07:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dzenbot/f5f46283886bafa92795cceb22e4fba0 to your computer and use it in GitHub Desktop.
Save dzenbot/f5f46283886bafa92795cceb22e4fba0 to your computer and use it in GitHub Desktop.
An easy way to detect the topmost presented view controller on iOS
+ (UIViewController *)topPresentedViewController
{
UIAppDelegate *delegate = [UIApplication sharedApplication].delegate;
UIViewController *visibleViewController = delegate.keyWindow.rootViewController;
while (visibleViewController.presentedViewController) {
visibleViewController = visibleViewController.presentedViewController;
}
return visibleViewController;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment