How do I check when a UITextField changes?

后端 未结 19 3146
情话喂你
情话喂你 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:27

    This is how you can add a textField text change listener using Swift 3:

    Declare your class as UITextFieldDelegate

    override func viewDidLoad() {
        super.viewDidLoad()
    
        textField.delegate = self
    
        textField.addTarget(self, action: #selector(UITextFieldDelegate.textFieldShouldEndEditing(_:)), for: UIControlEvents.editingChanged)
    }
    

    Then just traditionally add a textFieldShouldEndEditing function:

    func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { // do stuff
            return true 
    }
    

提交回复
热议问题