Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A category on the UIResponder class to obtain the first responder object.
@interface UIResponder (FirstResponder)
+ (UIResponder *)firstResponder;
@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"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment