How do I check when a UITextField changes?

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

    You should follow this steps:

    1. Make a Outlet reference to the textfield
    2. AssignUITextFieldDelegate to the controller class
    3. Configure yourTextField.delegate
    4. Implement whatever function you need

    Sample code:

    import UIKit
    
    class ViewController: UIViewController, UITextFieldDelegate {
    
        @IBOutlet var yourTextFiled : UITextField!
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            yourTextFiled.delegate = self
        }
    
    
        func textFieldDidEndEditing(_ textField: UITextField) {
            // your code
        }
    
        func textFieldShouldReturn(_ textField: UITextField) -> Bool {
            // your code
        }
    
        .
        .
        .
    }
    
    0 讨论(0)
提交回复
热议问题