Skip to content

Instantly share code, notes, and snippets.

@hugo53
Created November 24, 2014 00:04
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 hugo53/6598af5190804bd727e6 to your computer and use it in GitHub Desktop.
Save hugo53/6598af5190804bd727e6 to your computer and use it in GitHub Desktop.
Get view controller of a view
UIViewController *viewController;
for (UIView* next = [self superview]; next; next = next.superview) {
UIResponder* nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
viewController = (UIViewController*)nextResponder;
}
}
return viewController;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment