• 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: Bindings - custom null value placeholder for text field with date formatter?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bindings - custom null value placeholder for text field with date formatter?


  • Subject: Re: Bindings - custom null value placeholder for text field with date formatter?
  • From: Casey Fleser <email@hidden>
  • Date: Thu, 5 Jan 2006 23:23:18 -0600

You could try using subclassing NSValueTransformer like:

@interface GStringToString : NSValueTransformer
{
}

@end

@implementation GStringToString

+ (Class) transformedValueClass
{
    return [NSString class];
}

- (id) transformedValue: (id) inValue
{
	if (inValue == nil)
		inValue = @"aw crap, nil";

	return inValue;
}

@end

@implementation thingy

+ (void) initialize
{
[NSValueTransformer setValueTransformer: [[[GStringToString alloc] init] autorelease] forName: @"GStringToString"];
}


@end

And finally in IB set the name of the Value Transformer to GStringToString or whatever you end up calling it.

Casey

On Jan 5, 2006, at 10:44 PM, Jim Correia wrote:

I have an NSTextField bound to a key which provides an NSDate. The date represents the last time something happened. A null value means that action has never taken place. If the action has never taken place, I'd like the field to say "Never" and be in regular black text (not the usual gray null value placeholder color.)

Is there some way I can do this with the bindings system? I feel like I'm fighting the framework, so I must be doing something wrong.

What I've tried so far:

• Bind the text field's value (though the controller) to the date attribute. If I don't attach a formatter in IB, I can provide a null value placeholder of "Never", but it shows up in gray, and I'd rather it be black. (I later attach a formatter by hand so that the date value is formatted. This seems superficially wrong, since I've subverted the checks IB seems to do in case 2.)

• The same as the above, but attach a date formatter. Now the null value placeholder field in IB says <date value>. I can't seem to get it to accept a date value if I type one in the field, and that isn't what I want anyway.

* The same as above, but supply a custom formatter which returns "Never" from -stringForObjectValue:. The formatter doesn't seem to get this message in the case of a nil value.

What is the right (or any way, even ugly) way to solve this problem with bindings?

Or must I do things "by hand" for this field because I have somewhat special needs?

Thanks,
Jim _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40griffintechnology.com


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
  • Follow-Ups:
    • Re: Bindings - custom null value placeholder for text field with date formatter?
      • From: Jim Correia <email@hidden>
References: 
 >Bindings - custom null value placeholder for text field with date formatter? (From: Jim Correia <email@hidden>)

  • Prev by Date: inter-NIB binding problems, but only with NSTableColumn
  • Next by Date: Crash in _blinkCaretTimerAction (NSTextView)
  • Previous by thread: Bindings - custom null value placeholder for text field with date formatter?
  • Next by thread: Re: Bindings - custom null value placeholder for text field with date formatter?
  • Index(es):
    • Date
    • Thread