Skip to content

Instantly share code, notes, and snippets.

@Ashton-W
Created October 1, 2014 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ashton-W/cb1242c944666219087c to your computer and use it in GitHub Desktop.
Save Ashton-W/cb1242c944666219087c to your computer and use it in GitHub Desktop.
UIResponder (FirstResponder) magic. Intercept UIControls calling `sendAction:to:from:forEvent:` and store a weak ref.
@implementation UIResponder (FirstResponder)
static __weak UIResponder *currentFirstResponder;
+ (instancetype)currentFirstResponder
{
[[UIApplication sharedApplication] sendAction:@selector(findCurrentFirstResponder:) to:nil from:self forEvent:nil];
return currentFirstResponder;
}
- (void)findCurrentFirstResponder:(id)sender
{
currentFirstResponder = self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment