RE: Creating an ordered list for combo-box content from a Core Data entity attribute
RE: Creating an ordered list for combo-box content from a Core Data entity attribute
- Subject: RE: Creating an ordered list for combo-box content from a Core Data entity attribute
- From: "Jon C. Munson II" <email@hidden>
- Date: Wed, 8 Apr 2009 18:56:07 -0400
- Organization: JTA Enterprises LLC
Namaste!
OK, for the sake of the discussion:
1. I have an entity called Item.
2. Item has many attributes, the one of interest is Color. It is a string
attribute.
3. Assume acItem, an array controller is bound to Item.
4. Assume acItemColors is bound to Item (but not editable), and has the
contentArray set to email@hidden.
5. On a window, acItem handles the attributes of item.
6. acItemColors simply gets an aggregated list of colors of items.
7. There is a combo-box whose Value is bound to acItem.selection.Color.
The content/contentValues are bound to acItemColors.arrangedObjects. No
model keyPath.
8. in awakeFromNib for the window controller behind the window, a sort
descriptor is created to specify the sort for acItemColors: sortDescriptor
= [[NSSortDescriptor alloc] initWithKey:@"" ascending:YES]
This seems to work. Last question is whether this is a proper way to do
this.
Peace, Love, and Light,
/s/ Jon C. Munson II
> -----Original Message-----
> From: I. Savant [mailto:email@hidden]
> Sent: Wednesday, April 08, 2009 6:46 PM
> To: email@hidden
> Cc: 'Cocoa Developers'
> Subject: Re: Creating an ordered list for combo-box content from a Core
> Data entity attribute
>
> On Apr 8, 2009, at 6:24 PM, Jon C. Munson II wrote:
>
> > However, your previous reply sparked something and I got the array
> > controller partially working. It now returns the list, albeit
> > unordered.
> > The contentArray (can't use contentSet in this case) is bound to the
> > "master" array controller's
> > email@hiddengAttribute. This gets
> > me the
> > aggregated list of stringAttributes (or so I think anyway).
> >
> > Now, when I attempt to set the sort descriptor in the array
> > controller, I
> > get a not key-value coding compliant error. This is because there
> > is only
> > one attribute being returned and it apparently doesn't have a key
> > that I
> > know (and yes, I checked to make sure I spelled my keyPath
> > correctly). When
> > binding the combo-box content/content values, I simply used
> > arrangedObjects
> > with no keypath and that seems to be correct as the list is loaded and
> > displayed.
>
> Okay, this is where we run into the same old problem of "not enough
> info" to make a clear and concise answer. It's exceedingly difficult
> to model all this without a clear description of what relevant (array)
> controllers (by name) you're using, and how your popup is bound to its
> source array controller, and how you're setting your sort descriptors.
>
> In a simple test case, if you have an array controller which
> controls a set of "Person" instances (from wherever), and Person has
> the attribute "fullName, which you want to be both the displayed
> string in the popup button, *and* the attribute by which they're
> sorted, you need to:
>
> 1 - Set the array controller's sort descriptors (an array of
> descriptors) to include a descriptor for the key "fullName".
>
> 2 - Bind the popup's *content* to the array controller's
> arrangedObjects (no model key path).
>
> 3 - Bind the popup's *content values* to the array controller's
> arrangedObjects, model key path "fullName".
>
> 4 - Bind the popup's *selected object* to the array controller's
> selection (no model key path).
>
> The reason we're distinguishing selected objects from their display
> values is that, being a Core Data application as you mentioned, it's
> likely that the "Person" (or whatever it is for you) selected with the
> popup will set some relationship for some other object. You need the
> object, rather than the name in this case.
>
> --
> I.S.
_______________________________________________
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