écrit par Christian Corsano
,
Dimanche 25 Mai 2008 à 07:43:21 - GMT
Introduced with Leopard was Interface Builder 3 (IB3), which finally included support to include NSToolbar design in nib (or xib – the new trendy format) files.
Yes. But.
Following Apple documentation, I added a NSToolbar instance to my document window, and customized it with some NSToolbarItems.
As expected, it works great, my toolbar items have custom icons and calls the specified action.
The problem occurred as I wanted to make some of these items “selectable” – meaning they would have a mode-selection behavior.
The thing is IB3 doesn’t provide a way to set this property in its interface. The way to do this is to specify a delegate for the toolbar and override
- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar;
The name of this method is pretty much self explanatory, but I hadn’t specified any item identifiers for my custom toolbar items in IB, because this essential property is nowhere to be found !
Looking at the xib file directly in a text editor, it looks like IB generates a hash-code for each custom toolbar item to use as its identifier.
This makes it impossible (or at least darn difficult) to programmatically retrieve or use these items.
In the end I had to configure manually my toolbar’s content by loading a plist file which did more or less the work of the xib file : hold the configuration of my toolbar, but allowing me to specify which items were selectable. And it works great, except that I can’t visualize the content of my toolbar at design-time.
Now I have one more question to ask the Apple engineers at WWDC ;-)
You can read some code on the full-post.