This is my very first attempt at using an NSArrayController, so please bear with some very basic questions.
I would like to display to the user a popup button whose menu items have the names “Name1”, “Name2”, . Each name is associated with a value, “Value1”, “Value2”, . When the user selects a name, I would like to do things in my controller script (MainScript) with the corresponding value. Based on some examples I found through searching, I’ve tried the following:
(1) In MainScript, I’ve created a list of NSDictionary items as follows:
property recordList : {}
set nameList to {"Name1", "Name2", "Name3"}
set valueList to {"Value1", "Value2", "Value3"}
repeat with i from 1 to nameList's length
set end of my recordList to current application's NSDictionary's dictionaryWithObject_forKey_(valueList's item i, nameList's item i)
end repeat
(2) In the interface window, I’ve brought an NSArrayController object into the window and bound its Controller Content to MainScript with Model Key Path set to recordList.
(3) In the interface window, I’ve brought an NSPopUpButton into the window and made the following bindings:
NSPopUpButton’s Content bound to the NSArrayController with Controller Key set to arrangedObjects
NSPopUpButton’s Content Objects bound to the NSArrayController with Controller key set to arrangedObjects, and Model Key Path set to value
NSPopUpButton’s Content Values bound to the NSArrayController with Controller key set to arrangedObjects, and Model Key Path set to name
I build and run, and the popup button has no content. Also, if I create an outlet called arrayControllerOutlet in MainScript to the NSArrayController object and send it the message:
tell my arrayControllerOutlet to its content()
it returns an empty list.
Where am I going wrong? Why is the popup button not getting populated?