< Previous PageNext Page > Hide TOC

Selectable Toolbar Items

NSToolbar allows you to specify that certain items in the toolbar can indicate a selected state. This is often used in conjunction with an NSTabView that is configured to have no visible tabs. Figure 1 contains an example implementation similar to that of Safari and the Finder.


Figure 1  Selectable NSToolbar items used as preferences navigation

Selectable NSToolbar items used as preferences navigation

Toolbars that need to indicate item selection must specify the items that can be selected by implementing the delegate method toolbarSelectableItemIdentifiers:. This method returns an array containing the identifiers of the items that can be selected. The example Listing 1in returns all the identifiers for the preferences implementation.

Listing 1  Example implementation of toolbarSelectableItemIdentifiers:

- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar;
{
    // Optional delegate method: Returns the identifiers of the subset of
    // toolbar items that are selectable. In our case, all of them
    return [NSArray arrayWithObjects:GeneralPreferences,
                                    AccountPreferences,
                                    AppearancePreferences,
                                    FontsAndColorsPreferences,
                                    AdvancedPreferences, nil];
}

Your application can specify the currently selected toolbar item using the method setSelectedItemIdentifier: passing the identifier for the desired toolbar item. The currently selected toolbar item is returned by the method selectedItemIdentifier:. If there is no currently selected, nil is returned.



< 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.