Re: Binding a text field's editable binding to a matrix
Re: Binding a text field's editable binding to a matrix
- Subject: Re: Binding a text field's editable binding to a matrix
- From: Guy English <email@hidden>
- Date: Wed, 19 Jan 2005 14:05:24 -0500
Mmalcs example does exactly what you need but lest you think your
writing a class for this one circumstance is over kill you can make
your transformer much more generic.
With the this transformer you can test for any value. Registering
*instances* instead of classes gives you lots of opportunity for this
kind of thing.
Anyway - Mmalcs code hacked a litte:
@interface NumberEqualityTestTransformer
+ (Class)transformedValueClass;
+ (BOOL)allowsReverseTransformation;
- (void) setTestValue: (id) aNumber;
- (id)transformedValue:(id)aNumber;
@end
@implementation NumberEqualityTestTransformer
+ (Class)transformedValueClass
{
return [NSNumber class];
}
+ (BOOL)allowsReverseTransformation
{
return NO;
}
- (void) setTestValue: (id) aNumber
{
[aNumber retain];
[testNumber release];
testNumber = aNumber;
}
- (id)transformedValue:(id)aNumber
{
if ( [aNumber isEqualToNumber: testNumber] {
return [NSDecimalNumber one];
}
return [NSDecimalNumber zero];
}
@end
MyDocument or wherever is appropriate:
+ (void)initialize
{
NumberEqualityTestTransformer *transformer =
[[[NumberEqualityTestTransformer alloc] init] autorelease];
[transformer setTestValue: [NSNumber numberWithInt: 2]];
[NSValueTransformer setValueTransformer:transformer
forName:@"TwoIsTrueTransformer"];
NumberEqualityTestTransformer *transformer =
[[[NumberEqualityTestTransformer alloc] init] autorelease];
[transformer setTestValue: [NSNumber numberWithInt: 3]];
[NSValueTransformer setValueTransformer:transformer
forName:@"ThreeIsTrueTransformer"];
}
_______________________________________________
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