Connecting an Action

  • Select the control you want to connect.

  • Choose Tools > Connections Inspector.

  • Drag from the Sent Action connection well to the target object.

  • Choose an action method from the list that appears.

  • Save your changes.

  • ../Art/ActionConnection_button.png

    An action connection is a message-passing relationship between a control and a target object in your Cocoa application. When a user manipulates the control, it sends a message to the specified target. The message invokes an action method. You can use Interface Builder to connect a control to its action; this process is called connecting an action. In most cases, you connect an action in Interface Builder and do not change the connection in your code. Before making the connection, you need to add the desired action method to the target class and save your changes.

    Open the nib file, select the control, and display the Connections inspector. The inspector lists all the possible connections for the control. The circles on the right are connection wells. Drag from the Sent Action connection well to the target object. (Interface Builder highlights the object to indicate that a connection is possible.) Interface Builder displays a list of action methods defined in the target class. Select an action method to complete the connection. The inspector visually indicates that the connection is complete by filling in the connection well and listing the name of the target class and the action method.

    The video illustrates how to connect a control consisting of a matrix of buttons to the action method selectToolAction: in the File’s Owner target. The nib file is named ToolPalette.nib and belongs to the Sketch project.