• 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: Binding a text field's editable binding to a matrix
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Binding a text field's editable binding to a matrix


  • Subject: Re: Binding a text field's editable binding to a matrix
  • From: Keith Renz <email@hidden>
  • Date: Wed, 19 Jan 2005 17:37:19 -0500

mmalc and Guy,

I added the value transformers and everything works beautifully. The more generalized value transformer is really quite nice and is definitely the way to go.

This is one of those issues which you might want to document on your bindings page. Even though it's a relatively simple concept, for a "bindings beginner", it's not so obvious how it can be done, even after poring through all the docs.

Thanks for all the help.

Keith

-----

On Jan 19, 2005, at 2:05 PM, Guy English wrote:

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


_______________________________________________ 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
References: 
 >Binding a text field's editable binding to a matrix (From: Keith Renz <email@hidden>)
 >Re: Binding a text field's editable binding to a matrix (From: mmalcolm crawford <email@hidden>)
 >Re: Binding a text field's editable binding to a matrix (From: Keith Renz <email@hidden>)
 >Re: Binding a text field's editable binding to a matrix (From: mmalcolm crawford <email@hidden>)
 >Re: Binding a text field's editable binding to a matrix (From: Keith Renz <email@hidden>)
 >Re: Binding a text field's editable binding to a matrix (From: mmalcolm crawford <email@hidden>)
 >Re: Binding a text field's editable binding to a matrix (From: Guy English <email@hidden>)

  • Prev by Date: Problem with NSAlternateKeyMask
  • Next by Date: Authorization without permanent setuid on helper
  • Previous by thread: Re: Binding a text field's editable binding to a matrix
  • Next by thread: (no subject)
  • Index(es):
    • Date
    • Thread