< Previous PageNext Page > Hide TOC

Toolbar Management Checklist

Before you begin coding:

For further information, see “Adding and Removing Toolbar Items.”

Note: You can create a toolbar in Interface Builder as described in “Creating a Toolbar in Interface Builder.” The toolbar can have a default set and allowed set of toolbar items. If you use Interface Builder for this purpose, you may ignore many of the programmatic steps described below. At runtime, you can combine toolbars and toolbar items unarchived from a nib file and those created programmatically.

What happens: The application launches or a document is created or opened, causing a nib file to be loaded and its object unarchived.

For further information see “Adding and Removing Toolbar Items”

What happens: The NSToolbar object begins communicating with its delegate in order to populate the toolbar with toolbar items.

  1. The window gets the allowed and default toolbar item identifiers:

    • The toolbar object calls the delegate method toolbarAllowedItemIdentifiers: to get the total set of possible toolbar items.

    • Unless it finds the default toolbar configuration in user preferences, the toolbar calls the delegate method toolbarDefaultItemIdentifiers: to get the default set.

      To have the default configuration saved to and read from user preferences, the NSToolbar object’s autosavesConfiguration attribute must be set.

    • If certain toolbar items should indicate a selected state, the delegate should implement toolbarSelectableItemIdentifiers: to return the identifiers of those toolbar items.

  2. The window asks for each NSToolbarItem object (by identifier) to insert into the toolbar.

    • To add each toolbar item to the toolbar, the NSToolbar object sends toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar: to the delegate.

      If the NSToolbarItem object is image-based, get the image from the application bundle (for example, by using the NSImage class method imageNamed:) and send setImage: to the toolbar item. Also set the toolbar item’s label, palette label, target, and action. You may also set a menu form representation.

      If the toolbar item is view-based, send setView: to the toolbar-item object, passing in the outlet to the view. Also set the toolbar item’s label, palette label, its minimum size (minSize), and its maximum size (maxSize). (If you do not set a minSize and maxSize, the view does not appear because it is sized to zero in both dimensions.) You may also set a menu form representation.

    • If the delegate wants to customize a toolbar item before it is added, it can also implement the toolbarWillAddItem: notification method.

For further information see “Adding and Removing Toolbar Items,” “Setting a Toolbar Item’s Representation,” “Setting a Toolbar Item’s Size” and “Setting a Toolbar Item’s Size.”

What happens: Users click toolbar items; the runtime context of the application changes.

For further information, see “Validating Toolbar Items.”

What happens: The user chooses the Customize Toolbar menu item.

Note that the toolbar does not call any delegate methods when the user closes the customization sheet.



< Previous PageNext Page > Hide TOC


© 2002, 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-02-04)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.