Instance Method

toolbar(_:itemForItemIdentifier:willBeInsertedIntoToolbar:)

Sent to request a new toolbar item; returns a toolbar item of the identified kind for the specified toolbar.

Declaration

optional func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem?

Parameters

toolbar

The toolbar for which the item is being requested.

itemIdentifier

The identifier for the requested item.

flag

true if the item will be immediately inserted into the toolbar. If flag is false the toolbar item is being requested for display in the toolbar customization sheet and should always be enabled or provide some other canonical representation. If you ignore this parameter the same toolbar item will be used in the toolbar and in the customization sheet.

Return Value

The toolbar item for the specified toolbar and identifier. Return nil to indicate that the identified kind of toolbar item is not supported. When an item is requested again, you may return the same NSToolbarItem object returned earlier or a different instance.

Discussion

Implement this method to create new toolbar item instances. This method is called lazily on behalf of a toolbar instance, which must be the sole owner of the toolbar item. A toolbar may ask again for a kind of toolbar item already supplied to it, in which case this method may return the same toolbar item it returned before or a different one. If your delegate services multiple toolbars, each attached to a different window, it is best to return a different item for each toolbar—an NSToolbarItem object can only be in one toolbar at a time.

If the item is a custom view item, the NSView object must be fully formed when the item is returned. Do not assume that the returned item is going to be added as an active item in the toolbar, as it could be that it will be used only in the customization palette. (The customization palette makes a copy of the returned item.)

See Also

Configuring a Toolbar

func toolbarAllowedItemIdentifiers(NSToolbar) -> [NSToolbarItem.Identifier]

Sent to discover the allowed item identifiers for a toolbar.

func toolbarDefaultItemIdentifiers(NSToolbar) -> [NSToolbarItem.Identifier]

Sent to discover the default item identifiers for a toolbar.

func toolbarSelectableItemIdentifiers(NSToolbar) -> [NSToolbarItem.Identifier]

Sent to discover the selectable item identifiers for a toolbar.