UITextField text change event

后端 未结 21 1284
南方客
南方客 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:37

    Swift 3 Version

    yourTextField.addTarget(self, action: #selector(YourControllerName.textChanges(_:)), for: UIControlEvents.editingChanged)
    

    And get the changes in here

    func textChanges(_ textField: UITextField) {
        let text = textField.text! // your desired text here
        // Now do whatever you want.
    }
    

    Hope it helps.

提交回复
热议问题