When is TextFieldDidEndEditing: textField called?

I have 2 UITextField in a ViewController. One calls UIDatePicker, the other calls KeyBoard (numeric keypad). Then I assign user inputs to two class variables, the NSDate variable and the NSNumber variable, as follows.

-(void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField == self.datePickerTextField){
        //update xxtime
        self.xxTime = self.datePicker.date;
        NSLog(@"...%@",self.xxTime);
    }
     if (textField == self.numberTextField) {
        int val = [textField.text intValue];
        self.xxNumber = [NSNumber numberWithInt:val];
        NSLog(@"...%@",self.xxNumber);
    }

}

If I first touch datePickerTextField and then numberTextField, this method will not be called after the input in numberTextField is complete.

So my question is: how do I get this method to get a call? Should I specify "resignFirstResponder" somewhere?

TIA

+4
source share
3 answers

It will call didEndEditing when another control gets focus

API,

, .

, , didEndEditing ,

[textField resignFirstResponder];
+7

Yo , resignFirstResponder

- (BOOL)textFieldShouldReturn:(UITextField *)textField {//Text Field Delegate
    if (textField == textField1) {
        [textField1 becomeFirstResponder];
    }else{
        [textField resignFirstResponder];
    }
    return TRUE; }

textFieldDidEndEditing

+2

, , iOS. , iOS 10, , textFieldDidEndEditing func textFieldDidEndEditing(_ textField: UITextField, reason: UITextFieldDidEndEditingReason)

0

All Articles