I would like to get the view that is the first responder, currently I have a UITableView that contains UITextFields, using a method:
-(UIView*) findFirstResponder
{
}
I would like to be able to get the view that is the firstResponder and then do something with that view.
Any ideas?
All I had to do was
@implementation UIView (FindViewThatIsFirstResponder)
- (UIView *)findViewThatIsFirstResponder
{
if (self.isFirstResponder) {
return self;
}
for (UIView *subView in self.subviews) {
UIView *firstResponder = [subView findViewThatIsFirstResponder];
if (firstResponder != nil) {
return firstResponder;
}
}
return nil;
}
@end
Use UIControl as a root reference to different types of control that can become first responder.
UIControl *currentControl;
As Gobot says - whenever a textfield becomes first responder, keep a note of which one it is...
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
currentControl = textField;
. . .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With