On Jan 14, 2010, at 4:09 PM, Jenny M wrote:

> I have an Array Controller whose objects are displayed in an NSPopUpButton.

> However, what can I do if the array controller becomes empty? If I delete all 
> the objects, or if the window starts up with an empty array controller, I'd 
> like for the list to then have a null element that says "No objects."  Once 
> an object is added, it should go away.


> But if I choose "Insert null placeholder" in the pop-up options, the null 
> placeholder is ALWAYS there, which is not good.

Well, this part is as expected.  That's what the null placeholder is for.  It's 
not a way to represent when the array controller has no objects.  It's a way 
for the pop-up to give the user the option of selecting none of the objects 
from the array controller.

> Is there a way to do this in IB, or is this a thing I should code? And if so, 
> how can I make sure the method is called whenever there is a change to the 
> array controller?

With some experimentation, I discovered the following:

I bound the pop-up's content to the array controller's arrangedObjects.  I 
bound its Selected Value or Selected Object (but not Selected Index) to the 
array controller's selection with an appropriate model key path.  For the 
content binding, I set a No Selection Placeholder string.  Then, whenever the 
array controller had no selection, the pop-up showed the placeholder string.

If the Selected Value binding's Conditionally Sets Enabled option is on (the 
default), then the pop-up is disabled when there's no selection in the array 
controller.  This is sort of bad if the controlled array is not empty but the 
array controller has no selection.  In that case, the pop-up shows the 
placeholder but is disabled, so the user can't access the other items in the 
pop-up.  However, the array controller won't have no selection if its Avoid 
Empty Selection property is enabled (again, the default).  With that property 
enabled, the pop-up shows the placeholder and is disabled only if there's 
nothing in the controlled array.  If there are objects in the array, then the 
array controller has a selection and the pop-up shows it and is enabled.

So, Conditionally Sets Enabled on the pop-up's Selected Value or Object 
binding, plus Avoids Empty Selection on the array controller works well.  
Turning both of those off makes for a functional but possibly strange 
interface; when the array is non-empty but the array controller has no 
selection, the pop-up shows the placeholder but is enabled and also contains 
the normal items.

I hope that helps.

Cheers,
Ken

_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to