UITextField text change event

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

    Swift 3 Version:

    class SomeClass: UIViewController, UITextFieldDelegate { 
    
       @IBOutlet weak var aTextField: UITextField!
    
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            aTextField.delegate = self
            aTextField.addTarget(self, action: #selector(SignUpVC.textFieldDidChange), for: UIControlEvents.editingChanged)        
        }
    
       func textFieldDidChange(_ textField: UITextField) {
    
           //TEXT FIELD CHANGED..SECRET STUFF
    
       }
    
    }
    

    Don't forget to set the delegate.

提交回复
热议问题