Swift UITextFieldShouldReturn Return Key Tap

后端 未结 4 1904
旧时难觅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 02:07

    Implement this function

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

    And for delegate you can set using the Utilities pane / Connections Inspector / delegate and then drag to ViewController (yellow button in the storyboard)

    Then you do not need to set the delegate programmatically for every text field

提交回复
热议问题