Skip to content

Instantly share code, notes, and snippets.

@keicoder
Created January 8, 2014 08:11
Show Gist options
  • Select an option

  • Save keicoder/8313437 to your computer and use it in GitHub Desktop.

Select an option

Save keicoder/8313437 to your computer and use it in GitHub Desktop.
objective-c : Finding the Current First Responder
Finding the Current First Responder 
In iOS there is no simple call to retrieve the current first responder (without resorting to private APIs)
#import "UIResponder+FirstResponder.h"
static __weak id currentFirstResponder;
@implementation UIResponder (FirstResponder)
+(id)currentFirstResponder {
currentFirstResponder = nil;
[[UIApplication sharedApplication] sendAction:@selector(findFirstResponder:) to:nil from:nil forEvent:nil];
return currentFirstResponder;
}
-(void)findFirstResponder:(id)sender {
currentFirstResponder = self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment