Re: model key path and properties
Re: model key path and properties
- Subject: Re: model key path and properties
- From: Torsten Curdt <email@hidden>
- Date: Fri, 15 Jul 2011 11:44:55 +0200
> The popup button's Content binding is an *entire* array.
So you are saying it should be rather "Content Values" instead?
> Arrays don't have a "name" property. IOW, "arrangedObjects.name" is not a valid key path.
The strange thing - ignoring the warning it just worked. So I am a
little puzzled.
> Now, it's certainly true that NSArray responds to the KVC method 'valueForKey:@"name"', and it should produce an array of names, but since NSArrayController is something of a black box, you don't really know that this mechanism works via a binding to an array controller.
> You can try binding it anyway, and I guess if it works it works.
Ah - that's why then.
> We had a long thread about something similar a few months ago, and in that case it didn't work. The binding of a popup button does *not* work like the binding of a table column to its value, and that's probably the conceptual model that led you to try this.
That's exactly the model I had in mind.
> The other problem, though, is that even if it works, it's not a KVO-compliant mechanism. The popup menu content isn't going to update properly if the array changes, or if its elements' name properties change.
>
> Assuming that the "un-arranged" array that your array controller's content is bound to is (or is in) your data model, then the best solution is probably to do the whole thing "correctly":
Now I am listening...
> 1. In your window controller, observe the data model array. It also needs a mechanism to be told about changes to the "name" properties of the individual array elements, since the array's KVO notifications don't handle such property changes.
>
> 2. In your window controller, define a derived array property that is the desired values of the popup menu.
>
> 3. Have your window controller maintain this derived array property KVO-compliantly.
>
> 4. Bind the popup button directly to the window controller's derived array property.
>
> Unfortunately, there's no free lunch in this case. OTOH, doing it the "correct" way makes it pretty easy to do things like add separators and "Other..." items to the popup menu.
>
> Of course, if you go to all that trouble, it's probably easier just to set the popup button's menu directly. However, you still don't escape the data model KVO . :)
Hm. That's too much work for that simple popup button :)
TBH the only reason I was going down the binding road was to be able
to easily decorate the array and display the name instead of objects
themselves.
Hmmm. Disappointing. Thanks for sharing those insights.
cheers,
Torsten
_______________________________________________
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