A category on the UIResponder class to obtain the first responder object.
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
@interface UIResponder (FirstResponder) | |
+ (UIResponder *)firstResponder; | |
@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
@implementation UIResponder (FirstResponder) | |
+ (UIResponder *)firstResponder | |
{ | |
NSMutableDictionary *sender = [NSMutableDictionary dictionary]; | |
[[UIApplication sharedApplication] sendAction:@selector(setSelfForFirstResponderInSender:) to:nil from:sender forEvent:nil]; | |
return [sender valueForKey:@"firstResponder"]; | |
} | |
- (void)setSelfForFirstResponderInSender:(id)sender | |
{ | |
[sender setValue:self forKey:@"firstResponder"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment