views:

95

answers:

1

I am trying to populate a NSPopUpButtonCell with a list of strings. In -(init), I populate an NSArray with the values I want in the PopUp Button. How do I connect this to the NSArrayController I added in IB? Does my app delegate need an IBOutlet NSArrayController to connect to or is there a way to bind it?

Also, when I bind the NSArrayController to the NSPopUpButtonCell, do which Content do I bind it to? Content or Content Values?

jorj

+1  A: 

Bind the array controller's Content Array to your controller's array of strings. Bind both the pop-up button cell's Content and Content Values to your array controller's arrangedObjects.

Presumably, you also want to know which of these strings is selected. To do that, bind the pop-up button cell's Selected Object (which will be one of the objects in Content) to a property of your controller (the one that owns the original array).

Peter Hosey
How exactly do I bind the ArrayController (in IB) to the NSArray (in the app delegate)? I tried giving the app delegate an NSArrayController and rightclick/dragging it to the ArrayController in IB to link them but that didn't work. Should the app delegate have an NSArray or an NSArrayController? And how to I bind it?
sirjorj
Select the array controller and press ⌘4.
Peter Hosey
Got it. I had to set my app delegate variable to NSArray instead of NSArrayController (i had been switching back and forth to see which one would work), NOT make it an IBOutlet, bind the NSArrayController in IB to the app delegate, and set the "Model Key Path" to the name of the NSArray in the app delegate. Thanks!
sirjorj