NSPopupButtons and NSArrayControllers question and behavior
NSPopupButtons and NSArrayControllers question and behavior
- Subject: NSPopupButtons and NSArrayControllers question and behavior
- From: george tempel <email@hidden>
- Date: Tue, 22 Mar 2005 14:31:25 -0500
I'm wondering if someone out there can help out with an odd behavior(s)
I'm seeing in my Cocoa app involving NSPopupButton and
NSArrayController. I apologize for the long set-up here, but it's
involving multiple controllers and bindings, and I want to [try] to
convey a clear picture of what's been set up.
My NIB file has a window with two pop-up buttons: one for states, and
one for the array of stations for the state selected in the other
pop-up. My data model is basically the following:
(1) station: an NSDictionary of key/value pairs from some XML data
(2) stationArray: an NSArray of station data (see above)
(3) stateData: an NSDictionary with a single entry,
stateAbbreviation:stationArray
(4) states: an NSArray of stateData
(I hope that helps, but if not I can clarify later if necessary)
I have a StationsController object (derived from NSObject) that has the
states NSArray; StationsController is instantiated in the NIB file, and
there's an NSObjectController that has its "content" assigned to the
StationsController. The two pop-ups are driven by two
NSArrayControllers:
(5) statesController: an NSArrayController with contentArray bound to
NSObjectController's "controllerkey" of "selection" and "model key
path" of "states". Thus, statesController gets its content from #4
above.
(6) stationsController: an NSArrayController with contentArray bound to
#5 (the statesController above)'s "controllerkey" of "selection" and
"model key path" of "stations". Thus, this controller points to the
stationArray (#2) for the currently selected state (see below)
The two popup buttons are:
(7) statesPopup: an NSPopUpButton with the following bindings:
*content = statesController (#5) arrangedObjects, so pointing at (#4),
where each item is (#3)
*contentValues = statesController (#5) arrangedObjects.state so it
shows the state abbreviation, which is the single key in the stateData
(#3)
* selectedIndex = statesController (#5) selectionIndex
(8) stationsPopup: an NSPopUpbutton with the following bindings:
* content = stationsController (#6) arrangedObjects, so pointing at the
stationArray (#2) for the selected state
* contentValues = stationsController (#5) arrangedObjects.station_name
so it shows a particular key/value from the NSDictionary that
represents a station (#1)
* selectedObject = NSUserDefaultsController's values.selectedStation so
it'll pop the selected station (#1) into the user prefs for my
application under the "selectedStation" key.
Now, sorry for the long setup. All this seems to work fine, in that you
see a collection of state abbreviations in the statesPopup (#7), and
the values in the stationsPopup (#8) change when you select different
states. Additionally, when you select an item from the stationsPopup
(#8) the correct information gets written to the user prefs for the
app. But here's the odd behavior and the questions:
(Question) Once you select a state in (#7) and then a station in (#8),
if you go back and select a different state (#7) the stationsPopup (#8)
has the correct stations PLUS an additional bit of already selected
garbage, which _was_ the previously selected station. At first I
thought this may be because the previous state had more stations than
the just-selected state, but that's not the case. And once you click on
the stationsPopup (#8) and select something "real" the garbage goes
away. What am I doing wrong, if anything? Should I be binding to
something else in (#8) above, such as selectedValue?
Thanks in advance, and thanks for reading this far through the email
<grin>
ty
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden