Sagar Borate
Sagar Borate

Reputation: 17

Programmatically selecting NSToolBarItem

How can I programmatically select an NSToolbar item?

[toolbar setSelectedItemIdentifier:[theToolbarItem itemIdentifier]]

This code only selects it. I want to send it's action too, so that it changes panes.

Upvotes: 2

Views: 575

Answers (1)

bLacK hoLE
bLacK hoLE

Reputation: 801

You could set the target and action of the NSButton in the nib file itself, or if you need to do it programmatically, then create an IBOutlet to the NSButton and do it in code.

When you use an NSButton in a toolbar item, it effectively acts like an NSButton would anywhere else in your interface, rather than as an NSToolbarItem per se. For example, you won't be able to easily disable or enable the button through the use of the standard -validateToolbarItem: or -validateUserInterfaceItem:; rather, you'll need to have an IBOutlet to the button in question, or otherwise use bindings to enable or disable the button.

Upvotes: 3

Related Questions