How do I check when a UITextField changes?

后端 未结 19 2983
情话喂你
情话喂你 2020-11-22 15:44

I am trying to check when a text field changes, equivalent too the function used for textView - textViewDidChange so far I have done this:

  fu         


        
19条回答
  •  遇见更好的自我
    2020-11-22 16:33

    Swift 4

    textField.addTarget(self, action: #selector(textIsChanging), for: UIControlEvents.editingChanged)
    
    @objc func textIsChanging(_ textField:UITextField) {
    
     print ("TextField is changing")
    
    }
    

    If you want to make a change once the user has typed in completely (It will be called once user dismiss keyboard or press enter).

    textField.addTarget(self, action: #selector(textDidChange), for: UIControlEvents.editingDidEnd)
    
     @objc func textDidChange(_ textField:UITextField) {
    
           print ("TextField did changed") 
     }
    

提交回复
热议问题