On Jan 17, 2010, at 4:36 PM, Jenny M wrote:

> Thanks for your tips. We're closer I think. I took off the Selected Index 
> binding and instead bound the Selected Value to 
> ArrayController-selection-name. I'm probably binding it wrong though, because 
> I haven't quite gotten it to work yet.
> 
> I think what you say makes sense, about the selection objects and enabled 
> properties. I have a string in all three bindings' "No Selection Placeholder" 
> for the popup bindings (Content, Content Values, and Selected Value), but 
> instead, when the array controller is empty, the popupbutton is both disabled 
> and empty. "Conditionally Sets Enabled" is checked AND "Avoid Empty 
> Selection" is checked, but, no dice... You said this is what worked for you? 
> :/

Yes, that sounds like what I did.  However, on thinking some more about this, I 
think I was on the wrong track.  The selection value or object bindings of the 
pop-up would tend to set the bound-to property to whatever was selected in the 
pop-up.  So, if you bind the selected value to ArrayController.selection.name, 
when the pop-up selection changes, it would attempt to set the name property of 
the object selected in the ArrayController.  That's not what you want.

Although the Selected Index of the pop-up may sensibly be bound to the array 
controller's selection index, which will properly result in the selection 
tracked by the array controller matching the selection in the pop-up, that 
doesn't appear to trigger the No Selection placeholder of the content bindings, 
as you've discovered.  Basically, the array controller doesn't return the 
NSNoSelectionMarker marker for its selectionIndex property, it just returns 
NSNotFound.

So, try this: make a property on your window controller, app controller, or 
other appropriate coordinating controller (not the array controller, which is a 
mediating controller; probably this would be the same controller which provides 
the content for the array controller).  This new property will hold the state 
which the pop-up represents in the GUI.  Bind either the pop-up's selected 
object or selected value, whichever makes most sense for your design, to this 
property.

This property can be set when the array has contents, but when the array is 
empty it can return the NSNoSelectionMarker instead of, for example, nil.  That 
should be sufficient to trigger both the No Selection Placeholder and the 
Conditionally Sets Enabled bindings, leaving the pop-up disabled and showing 
the placeholder.

Alternatively, if the new property is bound to the pop-up's selection value, 
you can have it just directly return the placeholder when the array is empty.  
To disable the pop-up, you can bind its Enabled binding to 
arraycontroller.arrangedobjec...@count.

Since the value of this new property changes depending on whether or not the 
array has contents, you'll want to tell KVO that it's dependent on the array 
property (+keyPathsForValuesAffecting<Key>).

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to