Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the use of the "Sent Actions" option for an NSTextField?

In Interface Builder, when control-clicking on a NSTextField, the option Sent Actions is available. I thought it would trigger an action when clicking on my NSTextField (which is non-editable), but it doesn't work.

enter image description here

Any clue of the aim of this option?

like image 451
Colas Avatar asked Nov 01 '22 06:11

Colas


1 Answers

The explanations below describe how to connect an action to an object which will appear in the "Sent Actions" field. In your case that would be NSTextField. For example, here's a question on how to add a specific action to NSTextField: Send action from NSTextField when on key up instead of return .

All of this might not be relevant since you're working with a non-editable NSTextField. Nevertheless, if you did want to add a click action, there's a solution provide here: Which delegate method should I use to respond to clicks on an NSTextField?.

  • How to connect a button to a method on Mac OS X

    When you right-click on a button in a Mac nib, performClick: is under Received Actions; it’s not an event. The only entry under Sent Actions is “selector”, which is the only thing you can connect to an action on another object.

    Because there is only one “sent event”, you’ll normally just control-drag/right-drag from the control to the target and select the action rather than control-clicking, selecting the event and dragging from that.

  • Create the connection from the button to the action

    Now, right-click (or ctrl-click) on the button you added earlier, to show its inspector panel. In that panel, you'll see a section titled "Sent Actions", with a single item shown; that item is titled "selector", because it hasn't yet been connected to an action method. To make the connection, drag from that item's target (the circle at the right) to the controller object in the document window.

  • Adding an action to a GUI item - Slide 12/13

    1. Write the action code as a method of any class that IB knows (for example: ...AppDelegate or any class of your own making that you make known to IB)
    2. Click on the GUI item in the application window whose action you want to set
    3. Open the Connections Inspector

      Under the Sent Actions listing you will see ‘selector’, for that item. Click on the empty circle to the right and drag it to the MainMenu.xib window to the class where the action method is implemented; release it there.

      Upon release a listing of all implemented methods that can serve as actions is shown. Choose one with the mouse and click on it.

      This process corresponds to the target-action pattern that we used in writing the app without IB. The action method must be written with one parameter of type id.

like image 186
JSuar Avatar answered Jan 04 '23 14:01

JSuar