If you use the code in the other answer, your app will get rejected when submitted to the app store (for using a non-public api). I found that out the hard way. A better solution is to create a category. Here is what I used to replace the code in the original solution:
@interface UIView (FindFirstResponder)
- (UIView *)findFirstResponder;
@end
And
@implementation UIView (FindFirstResponder)
- (UIView *)findFirstResponder
{
if (self.isFirstResponder) {
return self;
}
for (UIView *subView in self.subviews) {
UIView *firstResponder = [subView findFirstResponder];
if (firstResponder != nil) {
return firstResponder;
}
}
return nil;
}
@end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…