O'Reilly logo

Beginning Mac OS® X Programming by Drew McCormack, Michael Trent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.4. Connecting Menus

In Cocoa menu items behave a lot like controls. For example, menu items can send an action to a target object. Unlike controls, which normally talk to specific controller objects, menu commands are usually handled by an application's current selection. For example, the Copy command will copy the information from the selected control, regardless of which control is selected. In either case you connect menus using the same kinds of techniques you've seen earlier in this chapter.

In the following Try It Out, you build Slide Master's menu bar. Most of Slide Master's custom interface is meant to be handled by the slide show document. You configure the menus in three steps:

  • First, you design the menus in Interface Builder, and connect them to custom actions in the nib file's First Responder instance.

  • Then, you declare an application delegate in your MainMenu nib file and write code in Xcode to handle one of the menu items.

  • Finally, you implement the menu actions in a Slide Show document.

8.4.1.

8.4.1.1. Try It Out: Connecting Menus to the First Responder
  1. In Xcode, double-click the MainMenu nib file. The nib file opens in Interface Builder.

  2. Rename the NewApplication menu to Slide Master. Also change the other occurrences of NewApplication in the Slide Master and Help menus to Slide Master.

  3. Add an Import menu item to the File menu, as shown in Figure 8-28.

    Figure 8.28. Figure 8-28
  4. Drag the Submenu item from the Menus palette and insert it into the main menu bar between ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required