Skip to content

Instantly share code, notes, and snippets.

@CaptainMalReynolds
Created March 13, 2015 20:00
Show Gist options
  • Save CaptainMalReynolds/1091e03c93d30f730394 to your computer and use it in GitHub Desktop.
Save CaptainMalReynolds/1091e03c93d30f730394 to your computer and use it in GitHub Desktop.
Current controller
- (UIViewController *)currentController {
UIResponder *currentController = [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] nextResponder];
if ([currentController isMemberOfClass:[UINavigationController class]]) {
NSArray *navStack = ((UINavigationController *)currentController).viewControllers;
currentController = [navStack objectAtIndex:[navStack count] - 1];
}
if ([currentController isKindOfClass:[UIViewController class]])
return (UIViewController *)currentController;
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment