• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Enable Unique Selection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Enable Unique Selection


  • Subject: Re: Enable Unique Selection
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Sat, 04 May 2013 11:54:42 +0700

On 3 May 2013, at 17:07, Andy Lee <email@hidden> wrote:

> 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.

An interesting idea.

I created a ValueTransformer like:

@implementation UniqueTransformer

+ (Class)transformedValueClass { return [ NSNumber class ]; }

- (id)transformedValue:(id)value
{
	BOOL unique = [ value respondsToSelector: @selector(integerValue) ]  &&  [ value integerValue ] == 1;
	return @(unique);
}

@end

Seems to me rather less code. Maybe still not the best way to do it, but the best I could think of.


Kind regards,

Gerriet.



_______________________________________________

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

  • Follow-Ups:
    • Re: Enable Unique Selection
      • From: Andy Lee <email@hidden>
    • Re: Enable Unique Selection
      • From: Steven Degutis <email@hidden>
References: 
 >Enable Unique Selection (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Enable Unique Selection (From: Andy Lee <email@hidden>)

  • Prev by Date: Re: Need advice: Object ownership and threading issue, causing a rare crash.
  • Next by Date: Re: Enable Unique Selection
  • Previous by thread: Re: Enable Unique Selection
  • Next by thread: Re: Enable Unique Selection
  • Index(es):
    • Date
    • Thread