Records and popupbuttons

Okay, so I have a popup button populated from a list of records. Say, {{name:bill,eyes:green,feet:two},{name:john,eyes:blue,feet:yes}}

I’ve set up my array controller and popup bindings correctly so the popup list shows the correct values, (in this example, name).

What I’d like to get returned when the user makes a selection though, is the entire record, so if they pick “john”, I get the entire thing.

Try binding to the Selected Object.

so I created a test variable:

property popupTest:“”

I bind popupTest to selected object, binding it to delegate and popupTest in the model key path, changing nothing else. All I get is the value I see in the popup.

You’re not saying where you want to “get” the value. If you have an action handler connected to the popup, you can get it like this:

	on chooseItem:sender
		set x to arrayController's selectedObjects()'s firstObject()
		current application's NSLog("selected: %@", x)
	end chooseItem:

where arrayController is an outlet to your array controller.

I’m trying to get the values when they make a selection in the popup.

I have the ArrayController’s content array bound to the list of records.
The popup’s content values are connected to the name value in the record, and selected object is bound to the variable that i’m trying to inject the record values into.

so, because I want to get the concepts correctly, I should be binding that variable I want the record to be injected into to the array controller?

Don’t try to do everything with bindings. For the selection, IMO you’re better of using an action handler. That way you get the value plus an indication that the selection has changed.

that did it (once I used selectedObjects()'s instead of selectedObject()'s)!

Thanks man!

okay, so hitting a related thing: how do I get the object corresponding to the actual selection. Right now, it’s only returning the first object. Which makes sense, but even if I set it to last object, I get the first one.

The array controller for this has its content array bound to a list of records, theNagiosServerRecords, and its referencing outlet is popupSelection which is set up as an IBOutlet

the popup has its content values bound to the above array controller, controller key arrangedObjects, model key path serverName

the sent actions for the popup is attached to selectedServerName:sender

I did go looking through the dev docs for selectedObjects in NSArrayController, but didn’t find anything that pointed me in the right direction, or if it did, I have the dumb.

Never mind, doped it out. I had to use NSpopupButton’s indexOfSelectedItem to get the numerical index, then use arrayController’s setSelectionIndex.

Now on to figuring out why userSelection’s removeObjects:(userSelection’s arrangedObjects()) isn’t doing what it’s supposed to do

Derp. Helps if you clear out the list of records variable you’re using before putting more data into it