UITextField text change event

后端 未结 21 1331
南方客
南方客 2020-11-22 06:49

How can I detect any text changes in a textField? The delegate method shouldChangeCharactersInRange works for something, but it did not fulfill my need exactly.

21条回答
  •  深忆病人
    2020-11-22 07:30

    From proper way to do uitextfield text change call back:

    I catch the characters sent to a UITextField control something like this:

    // Add a "textFieldDidChange" notification method to the text field control.
    

    In Objective-C:

    [textField addTarget:self 
                  action:@selector(textFieldDidChange:) 
        forControlEvents:UIControlEventEditingChanged];
    

    In Swift:

    textField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
    

    Then in the textFieldDidChange method you can examine the contents of the textField, and reload your table view as needed.

    You could use that and put calculateAndUpdateTextFields as your selector.

提交回复
热议问题