Re: complicated (I think) Binding
Re: complicated (I think) Binding
- Subject: Re: complicated (I think) Binding
- From: Mike Abdullah <email@hidden>
- Date: Sun, 12 Mar 2006 00:00:27 +0000
Thanks John, things are a little clearer. I still need to try and
make the store of sounds central to the app, but I think I may be
able to figure that part out.
From your solution, I have a question. You say to bind to
selectedValue to the popup button, but that it will give me the
result minus the extension. What if I were to bind to selectedObject
instead? (I am still trying to learn what these various options are
actually for!
I think the key point may be that I need a NSArrayController, I
hadn't really considered using one for this situation previously.
Mike.
On 11 Mar 2006, at 23:45, John Pannell wrote:
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