• 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: Single selection and bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Single selection and bindings


  • Subject: Re: Single selection and bindings
  • From: Jonathan Guy <email@hidden>
  • Date: Wed, 05 Jul 2006 13:43:41 +0100

Thanks guys that helped me out

just tackling drag n drop with NSTreeController now.

On Friday, June 30, 2006, at 06:17PM, Matt Neuburg <email@hidden> wrote:

>On Fri, 30 Jun 2006 15:19:39 +0100, Jonathan Guy <email@hidden> said:
>
>> This would seem an easy thing to do but can't figure it out. I want to bind
>> the "Enabled" part of a button to the selection of a tree controller BUT I
>> only want the button to be enable when there is a single item selected in the
>> outline view (NOT a zero or multiple selection).
>
>Another solution (besides the value transformer approach from my earlier
>message) would be a controller subclass. In the case of NSArrayController,
>we could bind the button's Enabled to an ivar (because that's an
>observable). The ivar is set by code that takes advantage of the fact that
>selectedObjects, too, is an observable:
>
>@implementation MyNSArrayController
>
>- (void) awakeFromNib {
>   [self addObserver:self forKeyPath:@"selectedObjects"
>             options:0 context:nil];
>}
>
>- (void)observeValueForKeyPath:(NSString *)keyPath
>             ofObject:(id)object change:(NSDictionary *)change
>             context:(void *)context {
>   [self setValue:
>      [NSNumber numberWithBool:
>         [[self selectedObjects] count] == 1]
>      forKey: @"selectionIsOne"];
>}
>
>@end
>
>So we bind the button's Enabled to the controller's "selectionIsOne" and
>presto, we're there.
>
>m.
>
>--
>matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
>A fool + a tool + an autorelease pool = cool!
>AppleScript: the Definitive Guide - Second Edition!
><http://www.amazon.com/gp/product/0596102119>
>
>
>
>
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Permissions in an app bundle
  • Next by Date: Re: index out of bounds
  • Previous by thread: Re: Re: [SOLVED] createDirectoryAtPath anomaly between system versions?
  • Next by thread: Help - PDF parsing where to look?
  • Index(es):
    • Date
    • Thread