Re: Enable Unique Selection
Re: Enable Unique Selection
- Subject: Re: Enable Unique Selection
- From: Andy Lee <email@hidden>
- Date: Fri, 03 May 2013 06:07:18 -0400
On May 3, 2013, at 1:29 AM, Gerriet M. Denkmann <email@hidden> wrote:
> I have a button which only makes sense when exactly one thing is selected.
> Currently it's Enabled property is bound to Array Controller.selectedObjects.@count.
> I.e. the button is enabled if one or more things are selected.
>
> But I want it to be disabled when nothing is selected AND also if more than one thing is selected.
> Is there a way to do this without code?
>
> If not - what to do ? Create a value transformer? Or what else?
I vaguely remember doing this by adding a readonly property to the array controller -- something like "exactlyOneIsSelected" -- with a corresponding getter method. Then you can bind to ArrayController.exactlyOneIsSelected.
Then the question would be how to trigger KVO on that property. I don't remember what I did. My first thought would be to implement +(NSSet *)keyPathsForValuesAffectingExactlyOneIsSelected, but I'm not sure what to return. Maybe @"selectionIndexes"? Would @"selectedObjects.@count" work? I don't know if you can use aggregation in keyPaths...Affecting... methods.
It might be useful to implement these methods on a category of NSArrayController if you need this logic in multiple places.
As usual I have a nagging feeling there's a better way, but this at least should work.
--Andy
_______________________________________________
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