7

I have a toolbar with various options and some options should not be visible in some cases. I have already figured out a way to disable them in my application, using this callback:

  - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem

But I haven't figured out a way to really hide them when I need. Anyone has any ideas on how to do this or if it's really possible at all?

Maurício Linhares
  • 39,901
  • 14
  • 121
  • 158

2 Answers2

13

If disabling them is not enough you could remove the items.

[myToolbar removeItemAtIndex:itemIndex];

Then when you need to put them back, just re-insert them:

[myToolbar insertItemWithItemIdentifier:itemIdentifier atIndex:itemIndex];

Look at Adding and Removing Toolbar Items in the Apple docs.

David
  • 7,310
  • 6
  • 41
  • 63
1

No built-in visibility property for buttons. Remove it from the toolbar and re-add when needed.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • And how do I re-add them? I don't see a "addItemToToolbar" method. The closest thing i could find is "- (void)insertItemWithItemIdentifier:(NSString *)itemIdentifier atIndex:(NSInteger)index". is that the method I am looking for? Will I need to implement anything else on my delegate? – Maurício Linhares Feb 10 '11 at 22:18