Execute an Action when the Enter-Key is pressed in a NSTextField?

后端 未结 8 1980
野的像风
野的像风 2020-12-02 06:23

I have a small problem right now. I want to execute a method when the Enter key is pressed in a NSTextField. The user should be able to enter his data and a calculation meth

8条回答
  •  青春惊慌失措
    2020-12-02 06:43

    It's very easy and you can do it directly from UI editor

    1. Right click the Text Feild, drag Action reference to the button as shown below in the screenshot

    1. Now it will give you some option as shown in screen shot below, you need to select perform click

    1. Now it should look like this

    Note: The event will be raised as soon as you press Tab or Enter key. In case you want the action should only be raised when user presses the Enter key then you have to do a setting. Go to the Attribute inspector and change the Action property to Send on Enter only as shown in screen shot below

提交回复
热议问题