If you followed along by creating your own version of the project, you could build and run the project from Xcode. The window would open and when you chose an input device from the pop-up menu, the text fields would contain the HID information about the device. But the OK and Cancel buttons wouldn’t work. There’s a little more work to be done to finish the application.
When the user clicks the OK or Cancel buttons, the window should close. To get this behavior,
When you selected orderOut:, you probably noticed the performClose: action. Since the window should close when the user clicks the OK or Cancel buttons, performClose: sounds like the action to perform. Why choose the orderOut: action? I don’t know why, but using the performClose: action doesn’t cause the window to close when the user clicks the OK or Cancel buttons. The orderOut: action hides the window, which lets you easily show the window if the user wants to see the window again.
You also should assign keyboard equivalents for the OK and Cancel buttons: the Return key for OK and the Esc key for cancel. Select each button and press Cmd-1. Choose the appropriate key from the Key Equivalent menu.
I chose to have the example program’s window open when the user chooses File > View HID Information. To get this behavior the window must be invisible initially. Click inside the window, but not on any of the window’s user interface elements. Press Cmd-1 and deselect the Visible at Launch Time checkbox.
The example program is simple. It requires only one menu item. Remove the Edit, Window, and Help menus from the menu bar. Remove all of the menu items from the File menu except one. Double-click that item and rename it View HID Information.
When the user chooses File > View HID Information, the window should open. To get this behavior, perform the following steps:
This article only scratched the surface of Cocoa bindings. To learn more about bindings, read the document Cocoa Bindings Programming Topics. This document is part of Apple’s developer documentation, which you can read in Xcode or at Apple’s developer site. The document is in the Cocoa section under Design Guidelines.
Scott Stevenson wrote a 14 page article for CocoaDevCentral that provides a gentle introduction to bindings. The combination of his article and this article should provide enough of a background so you can start using bindings in your Cocoa applications.
Previous (Bind the Text Fields)