Created
January 22, 2012 19:07
-
-
Save srgtuszy/1658322 to your computer and use it in GitHub Desktop.
Parent UIViewController from UIView
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
#import <UIKit/UIKit.h> | |
@interface UIView (Utils) | |
-(UIViewController *)parentViewController; | |
@end |
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
#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