Check current responder?

Go To StackoverFlow.com

0

I'm making an application that requires the use of multiple textFields with number pads as there first responder. I have created an image to use as a negative button that will be an addition to the number pad.

I am wondering if there is a way to check which textField the number pad is typing to.

Any help would be appreciated!

2012-04-04 23:58
by Neil


1

If all of your potential first responders are UITextFields, another approach would be to conform your controller class to UITextFieldDelegate protocol, and then grab a reference to the currently editing UITextView at the time it begins editing. Conform your class in your .h:

MyController : NSObject <UITextFieldDelegate>  //Might often be a UIViewController rather than an NSObject subclass...

Define a property:

@property (weak, nonatomic) UITextField *editingField;

Then synthesize in your .m:

@synthesize editingField = __editingField

Then implement:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [self setEditingField:textField];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [self setEditingField:nil];
}

Now, whenever you want to know which text field is your first responder:

UITextField *firstResponder = [self editingField];
2012-04-05 01:51
by isaac


0

If there are only a limited number of them, you can query each with [textFieldN isFirstResponder]. If you want a general purpose utility, you can look at each subview in a view and see whether it is the first responder or whether any of its subviews farther down the hierarchy are.

2012-04-05 01:39
by Phillip Mills
Ads