Getting the first responder... Unless you want to use the private [view firstResponder] this seems to be the only legal way. Or am I wrong?
UIView *PSPDFFindFirstResponderBeneathView(UIView *view) { | |
// Stop if e.g. we show an UIAlertView with a text field. | |
if (UIApplication.sharedApplication.keyWindow != view.window) return nil; | |
// Search recursively for first responder. | |
for (UIView *childView in view.subviews) { | |
if ([childView respondsToSelector:@selector(isFirstResponder)] && childView.isFirstResponder) return childView; | |
UIView *result = PSPDFFindFirstResponderBeneathView(childView); | |
if (result) return result; | |
} | |
return nil; | |
} |
This comment has been minimized.
This comment has been minimized.
Hi I would like you my implementation for getting first Responder. Thanks |
This comment has been minimized.
This comment has been minimized.
@iottirubin your method seems a bit wasteful and ignores multiple windows. See the StackOverflow link above for a faster, more generic variant. |
This comment has been minimized.
This comment has been minimized.
Hi @steipete, Just wanted to make sure, the link you provided makes use of the "findFirstResponder" action.. Is this not a private API? I can only find mention of it in Apple's macOS documentation, not iOS. Thx! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Never mind. This is much better: http://stackoverflow.com/questions/5029267/is-there-any-way-of-asking-an-ios-view-which-of-its-children-has-first-responder/14135456#14135456