• 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: Keys dependent on NSArrayController's selection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keys dependent on NSArrayController's selection


  • Subject: Re: Keys dependent on NSArrayController's selection
  • From: "Sean McBride" <email@hidden>
  • Date: Wed, 7 May 2008 19:58:42 -0400
  • Organization: Rogue Research

On 5/7/08 6:16 PM, Dave Dribin said:

>In Interface Builder I bind the button's "Enabled" to
>"MyController.canEnableButton".  The implementation for
>canEnableButton is this:
>
>- (BOOL)canEnableButton {
>     NSArray * selectedPeople = [peopleController selectedObjects];
>     if ([selectedPeople count] < 1)
>         return NO;
>
>     Person * selectedPerson = [selectedPeople objectAtIndex:0];
>     return [selectedPerson.lastName hasPrefix: @"D"];
>}
>
>Of course, canEnableButton is now dependent on the selection of
>NSArrayController.  Thus, I added this:
>
>+ (NSSet *)keyPathsForValuesAffectingCanEnableButton {
>     return [NSSet setWithObjects:
>@"peopleController.selectionIndexes", nil];
>}
>
>However, this does not trigger the button to update when the selection
>changes.

Have you put a breakpoint in 'canEnableButton'?  When
'peopleController.selectionIndexes' changes, do you hit the breakpoint?
I suspect not.  The docs for keyPathsForValuesAffectingValueForKey say
keyPaths are ok, but mmalc has mentioned on this list "provided that the
path doesn't include to-many relationships".  This appears to be true in
your case, so probably explains it.  The docs don't mention this
caveat. :(  However, I haven't got keypaths to trigger even with to-one
relationships, which I have been meaning to investigate...

>In observeValueForKeyPath:ofObject:change:context:
>
>     if (context == SelectionIndexesContext)
>     {
>         [self willChangeValueForKey:@"canEnableButton"];
>         [self didChangeValueForKey:@"canEnableButton"];
>     }
>
>This works, however, it just seems wrong to use {will/
>did}ChangeValueForKey: like this.

Also, I seem to remember reading that doing willChange/didChange back-to-
back without actually changing anything is a no-no.  You might check the
archives to confirm my shoddy memory.

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada

_______________________________________________

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: Keys dependent on NSArrayController's selection
      • From: Dave Dribin <email@hidden>
References: 
 >Keys dependent on NSArrayController's selection (From: Dave Dribin <email@hidden>)

  • Prev by Date: Re: NSArrayController's insert:, where should the new item go?
  • Next by Date: BLOBs, MySQL, hex. Oh my
  • Previous by thread: Keys dependent on NSArrayController's selection
  • Next by thread: Re: Keys dependent on NSArrayController's selection
  • Index(es):
    • Date
    • Thread