Swift UITextFieldShouldReturn Return Key Tap

后端 未结 4 1882
旧时难觅i
旧时难觅i 2021-02-01 01:26

(iOS8, Xcode6, Swift) Using Swift, how do I capture a tap on the \"Return\" button?

The doc at the following link specifies using the textFieldShouldReturn

4条回答
  •  有刺的猬
    2021-02-01 01:59

    class ViewController: UIViewController,UITextFieldDelegate //set delegate to class
    
    @IBOutlet var txtValue: UITextField //create a textfile variable
    
    override func viewDidLoad() {
       super.viewDidLoad() 
       txtValue.delegate = self //set delegate to textfile 
    }
    
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {   //delegate method
       textField.resignFirstResponder()
       return true
    }
    

提交回复
热议问题