Created
March 13, 2015 20:00
-
-
Save CaptainMalReynolds/1091e03c93d30f730394 to your computer and use it in GitHub Desktop.
Current controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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