Re: Binding of "Object" and "Value" in NSPopupButtonCell
Re: Binding of "Object" and "Value" in NSPopupButtonCell
- Subject: Re: Binding of "Object" and "Value" in NSPopupButtonCell
- From: Jerry Krinock <email@hidden>
- Date: Wed, 7 Jan 2009 16:35:29 -0800
On 2009 Jan, 06, at 19:19, Ken Thomases wrote:
I would think you would want "Content" to refer to the allowed ranks
in their "raw" object form, not their string. So, don't use a value
transformer here. You wouldn't bind "Content Objects" because it
would just be the same as "Content". In order to get proper display
strings, you'd bind "Content Values". You could declare a category
on NSNumber to add a read-only "rankNameValue" property, and then
bind "Content Values" to the key path allowedRanks.rankNameValue.
Or, you could bind to allowedRanks and keep your nonreversible value
transformer.
Since the objects of the pop-up are now the raw number objects,
binding "Selected Object" becomes trivial. You just bind it to the
"rank" property with no value transformer.
Yes! This was what I first tried, except keeping my nonreversible
value transformer as you suggested. But the runtime just ignores my
transformer and displays the number. One time I typed "Stupid
Bonehead" into the "Value Transformer" field and it still worked the
same - not the expected "Can't find Stupid Bonehead" error.
So then I used your other suggestion, a category on NSNumber instead
of the value transformer and, voila -- success!
The docs don't make it crystal clear, but if I recall the release
notes[1] do: the "Content Objects" or "Content Values" bindings must
use a key path which is an extension of the "Content" key path.
Ah, always read the Release Notes. But you get a nice explanation in
the console at runtime too.
The purpose of the contentValues binding is relatively
straightforward: provide a better display value than the "whole"
object would through its -description method. The purpose of the
contentObjects binding has mostly to do with the selection. It's the
value that gets sets to the property bound to the selectedObject
binding, and on settting up the pop-up, it's used to match the
initially selected entry to the value obtained through the
selectedObject binding. Since your selection matches the "whole"
object (the NSNumber held by an Employee's rank property), you don't
need a separate contentObjects binding.
All makes sense once you see it work. Although it would have made
more sense had they named "Content Values" as "Display Values" instead.
On another topic, you say you're binding "Content" with a Controller
Key of "selectedObject" (which you define through a category as the
first element of the array controller's selectedObjects property).
This doesn't make sense to me. The Controller Key should be
arrangedObjects. Otherwise, all of the rows of the column will show
the rank for whichever row you select.
I tried this change first, but it does not matter, probably because
the only row showing its popup menu is the one that is selected anyhow.
So the Content binding of the pop-up column might be (as displayed
in IB) EmployeesController.arrangedObjects.allowedRanks. This
resolves to an array of arrays. The outer array has as many
elements as there are employees. The elements within that are
themselves arrays, the allowed ranks, as NSNumber objects, for each
employee. Similarly, for Content Values, binding to
EmployeesController.arrangedObjects.allowedRanks.rankNameValue would
produce an array of arrays -- for each employee, there would be an
array of strings which are the names of the allowed ranks.
I'm going to remember your category trick for the next time I have
trouble with a Value Transformer. I like the category better anyhow
-- the fewer things I have hidden away in those myriad little fields
in Interface Builder, the less I screw things up and the easier it is
to re-use my work.
Thanks, Ken.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden