How can I make an unknown UITextField resignation of the first responder?

My view has two UITextFieldsand UISwitch. If the user edits textField, and then immediately touches the switch (without pressing return), the text remains in the form in which it was entered, without AutoCorrect.

If I know which one textFieldthey fit into, I can make the auto-correction finish by calling [textField resignFirstResponder]. But the user can type text textField, so I don’t know which one to call.

How can I get around this? Is there any way to detect which one was textFieldused? Or something simpler that I did not think about?

+3
source share
4 answers

uitextfielddelegate , . , , .

uitextfielddelegate , .

:

textFieldDidEndEditing:

, .

- (void)textFieldDidEndEditing:(UITextField *)textField

textField
           , .

, . . , , , .     .

iOS 2.0 .

UITextField.h

+2

, :

// This causes the current responder (eg. an input field) to resignFirstResponder and
[self.endEditing:YES];
+9

[self.view endEditing:YES] ...

[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
+6

, , textFieldDidBeginEditing.

0

All Articles