UITextField - capture return button event

前端 未结 7 1163
春和景丽
春和景丽 2020-12-04 16:17

How can I detect when a user pressed \"return\" keyboard button while editing UITextField? I need to do this in order to dismiss keyboard when user pressed the \"return\" bu

7条回答
  •  一向
    一向 (楼主)
    2020-12-04 16:31

    You can now do this is storyboard using the sent event 'Did End On Exit'.

    In your view controller subclass:

     @IBAction func textFieldDidEndOnExit(textField: UITextField) {
        textField.resignFirstResponder()
    }
    

    In your storyboard for the desired textfield:

提交回复
热议问题