[Solved] How do I implement UITextFieldDelegate [closed]


Your ViewController should be an UITextFieldDelegate. You then set the current ViewController as the delegate of the textField, in this case in viewDidLoad().

Implement textFieldShouldReturn so the textField delegates the return task (textFieldShouldReturn) to the ViewController. In this method call resignFirstResponder, this way the keyboard will disappear. Example:

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var someTextField: UITextField!

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        someTextField.delegate = self

    }
}

1

solved How do I implement UITextFieldDelegate [closed]