Skip to content

Instantly share code, notes, and snippets.

@jamesmoschou
Created May 25, 2013 06:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmoschou/5648133 to your computer and use it in GitHub Desktop.
Save jamesmoschou/5648133 to your computer and use it in GitHub Desktop.
A category on the UIResponder class to obtain the first responder object.
@interface UIResponder (FirstResponder)
+ (UIResponder *)firstResponder;
@end
@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