Re: Putting Non Date in Date formatted text field
Re: Putting Non Date in Date formatted text field
- Subject: Re: Putting Non Date in Date formatted text field
- From: Matt Neuburg <email@hidden>
- Date: Tue, 26 Feb 2002 05:02:03 -0800
On Mon, 25 Feb 2002 19:48:49 -0800, John Pattenden <email@hidden> said:
>
I have a date field that is an expiration date. When I expire...
Joke omitted here. :-)
>
...I want
>
to change from displaying a date to displaying "Expired" - i tried
>
[IBexpirationDate setObjectValue:@"Expired"];
>
which didn't work.... ( i get a blank).. can I tell the formatter to
>
ignore this? or something else???
Obviously you could subclass NSDateFormatter to allow the string "Expired",
e.g.:
- (NSString *)stringForObjectValue:(id)anObject
{
if ([anObject isKindOfClass: [NSString class]]) return anObject;
return [super stringForObjectValue: anObject];
}
- (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string
errorDescription:(NSString **)error {
if ([string isEqualToString:@"Expired"]) {
*anObject = @"Expired";
return YES;
}
return [super getObjectValue:anObject forString:string
errorDescription:error];
}
But surely, if this field is merely *displaying* dates (i.e. you aren't
also allowing the user to enter a date manually), it would be simpler not
to use a formatter at all. NSCalendarDates come with their own built-in
string-conversion facility and, minus the formatter, you could put anything
you like into the field. m.
--
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes gar anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.