• 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: complicated (I think) Binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: complicated (I think) Binding


  • Subject: Re: complicated (I think) Binding
  • From: John Pannell <email@hidden>
  • Date: Sat, 11 Mar 2006 16:45:23 -0700

Hi Mike-

I can get you part of the way there...

Basically, I have in my document window, an NSPopupButton. I would ideally like to:

* Have a central object in my app keep a list of the files in a particular folder

This is how I get a list of the system sounds:

NSArray *soundList = [[[NSFileManager defaultManager] directoryContentsAtPath:@"/System/Library/Sounds"] retain];

* The popup button displays a list of the names of these files, minus their extension

Set up an array controller whose content is the array of loaded file names. Bind the popup's "content" and "contentValues" to this array controller. Use a value transformer to strip the extension off the values. Here is the implementation I wrote:


@implementation NoPathExtensionValueTransformer
+ (Class)transformedValueClass
{
    return [NSArray class];
}

+ (BOOL)allowsReverseTransformation
{
    return NO;
}

- (id)transformedValue:(id)aValue
{
    NSMutableArray *returnArray = [[NSMutableArray alloc] init];
    NSEnumerator *e = [aValue objectEnumerator];
    NSString *aSound;
    while(aSound = [e nextObject]){
        aSound = [aSound stringByDeletingPathExtension];
        [returnArray addObject:aSound];
    }
    return returnArray;
}
@end

You will need to create and register the value transformer to use it... do this in your application delegate's +initialize method...

NSValueTransformer *transformer = [[NoPathExtensionValueTransformer alloc] init];
[NSValueTransformer setValueTransformer:transformer forName:@"NoPathExtensionValueTransformer"];


* The selected item of the popup button is kept in the document's data store, but it is stored with the extension

Well, if you bind selectedValue to something (I bind it to a NSUserDefaults controller) it will be without the extension. You could certainly drop the binding for this purpose and set the popup's target and action to a method that records the selected file name for you.


HTH! Email me off list if you want the files for the value transformer...

John

John Pannell
Positive Spin Media
http://www.positivespinmedia.com
_______________________________________________
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


  • Follow-Ups:
    • Re: complicated (I think) Binding
      • From: Mike Abdullah <email@hidden>
References: 
 >complicated (I think) Binding (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: NSURLConnection timing out without delegate getting connection:didFailWithError: callback
  • Next by Date: Re: NSURLConnection timing out without delegate getting connection:didFailWithError: callback
  • Previous by thread: complicated (I think) Binding
  • Next by thread: Re: complicated (I think) Binding
  • Index(es):
    • Date
    • Thread