Created
October 6, 2011 09:06
-
-
Save zbyhoo/1266907 to your computer and use it in GitHub Desktop.
Pretty nice way to find UIViewController of UIView using category
This file contains hidden or 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
@interface UIView (FindUIViewController) | |
- (UIViewController *) firstAvailableUIViewController; | |
- (id) traverseResponderChainForUIViewController; | |
@end | |
@implementation UIView (FindUIViewController) | |
- (UIViewController *) firstAvailableUIViewController | |
{ | |
// convenience function for casting and to "mask" the recursive function | |
return (UIViewController *)[self traverseResponderChainForUIViewController]; | |
} | |
- (id) traverseResponderChainForUIViewController | |
{ | |
id nextResponder = [self nextResponder]; | |
if ([nextResponder isKindOfClass:[UIViewController class]]) | |
return nextResponder; | |
else if ([nextResponder isKindOfClass:[UIView class]]) | |
return [nextResponder traverseResponderChainForUIViewController]; | |
else | |
return nil; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment