4

Notice in Xcode's symbols list (the NSPopUpButton directly above the editor, to the right of the recently edited documents), it shows <No selected symbol> when you're out of scope of any symbols it lists, but then when you click on it that option is not there. Is there a trick to making this "placeholder" magic happen, or is there a setter somewhere I'm not seeing?

Placeholder text Not actually a menu item

d11wtq
  • 34,788
  • 19
  • 120
  • 195

1 Answers1

2

If you're using bindings, you can set null/no selection placeholders and turn on "Inserts Null placeholder" using Interface Builder's bindings inspector. If you're not using bindings, you can put whatever menu item in there you like at runtime.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • Yeah, I'm not using Interface Builder (which I assume means I can't use bindings?). So when you say "you can put whatever menu item you like in there", how do I make sure the actual list of available items is shown when the user clicks on the menu? And then if they click away without selecting anything, the menu should again display the placeholder item. Just handle mouse events and literally replace all the items with a placeholder? – d11wtq Nov 15 '10 at 23:22
  • You can establish bindings in code. Placeholders and other things are passed in the -bind... method. – Joshua Nozzi Nov 16 '10 at 00:40
  • 1
    Just to expand on what I wrote hastily at dinner: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaBindings/Concepts/HowDoBindingsWork.html and http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Protocols/NSKeyValueBindingCreation_Protocol/Reference/Reference.html – Joshua Nozzi Nov 16 '10 at 02:02
  • 5
    Sorry Joshua, this one somehow slipped through the net. Thanks for the answer and the links. I found a way to do this by just calling `[[popUpButton cell] setMenuItem:defaultItemThatIsNotInTheMenu]`, but I will read these links too as I'm curious on bindings. – d11wtq Dec 07 '10 at 11:22
  • 1
    For those wondering where the autocomplete is for `setMenuItem:`, the cell must be cast to `NSPopUpButtonCell`: `[(NSPopUpButtonCell *)popUpButton.cell setMenuItem:defaultItemThatIsNotInTheMenu]` – Nick Jun 20 '18 at 14:31