Date strings in NSTextFields
Date strings in NSTextFields
- Subject: Date strings in NSTextFields
- From: James Spencer <email@hidden>
- Date: Sun, 24 Oct 2004 19:32:11 -0500
I must be missing something obvious but I haven't been able to work
this out.
I have a drawer in which there are several NSTextFields one of which I
want to put a date into. I have attached a formatter to the field
with a format string matching the output I am looking for. In my
update method for the field, I pass a data record object which, among
other instance variables, contains a NSCalendarDate for when the data
that the record refers to had been received by the user. (Not that it
matters but the records are contained in an NSArray referenced from my
model object.) all I want to do is to display the date string in the
format of the field's formatter in the field. I've been trying
variations of the following where theDate is the NSCalendarDate object:
NSDateFormatter *dateFormatter;
NSString *dateString;
// Get the formatter from the field:
dateFormatter = [[self dateReceivedPreviousTextField] formatter];
dateString = [dateFormatter stringForObjectValue:theDate];
NSLog(@"The date received string: %@", dateString);
if(![dateString isEqualToString:[[self
dateReceivedPreviousTextField] stringValue]])
{
[[self dateReceivedPreviousTextField]
setStringValue:dateString];
}
The NSLog call and the debugger show that I'm getting the correct
formatter from the field (thereby, as an aside, also demonstrating that
my outlet for the field is being set correctly) and that the dateString
contains a string in the correct format. The "if" clause is correctly
finding that the string is different so the setStringValue: message is
being sent but the string is not appearing in the field. I've also
tried [[self dateReceivedPreviousTextField] setObjectValue:theDate] and
have also tried invalidating the field with [[self
dateReceivedPreviousTextField] setNeedsDisplay:YES]; to force a redraw
but still end up with an empty field.
Anyone got any ideas?
James P. Spencer
Rochester, MN
email@hidden
"Badges?? We don't need no stinkin badges!"
_______________________________________________
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