How do I get the return key to perform the same action as a button press in Swift?

前端 未结 5 2009
一向
一向 2020-12-12 23:42

I want to know how you allow an action to be made by either pressing the return key on the software keyboard or by tapping a UIButton.

The UI button is already set u

5条回答
  •  忘掉有多难
    2020-12-13 00:01

    UPDATE

    If your deployment target is iOS 9.0 or later, you can connect the “Primary Action Triggered” event of your text field to an action, like this:

    ORIGINAL

    Make your view controller adopt the UITextFieldDelegate protocol.

    Set your text field's delegate to your view controller.

    Implement textFieldShouldReturn: to call your action.

提交回复
热议问题