Skip to content

Instantly share code, notes, and snippets.

@srgtuszy
Created January 22, 2012 19:07
Show Gist options
  • Save srgtuszy/1658322 to your computer and use it in GitHub Desktop.
Save srgtuszy/1658322 to your computer and use it in GitHub Desktop.
Parent UIViewController from UIView
#import <UIKit/UIKit.h>
@interface UIView (Utils)
-(UIViewController *)parentViewController;
@end
#import "UIView+Utils.h"
@implementation UIView (Utils)
-(UIViewController *)parentViewController {
//Go up in responder hierarchy until we reach a ViewController or return nil
//if we don't find one
id object = [self nextResponder];
while (![object isKindOfClass:[UIViewController class]] &&
object != nil) {
object = [object nextResponder];
}
return object;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment