Re: Problem with date and time columns both bound to the same date attribute
Re: Problem with date and time columns both bound to the same date attribute
- Subject: Re: Problem with date and time columns both bound to the same date attribute
- From: Andrew Madsen <email@hidden>
- Date: Thu, 27 Dec 2007 12:52:30 -0700
On Dec 26, 2007, at 8:10 PM, Michael Babin wrote:
As Matt wrote in his reply to you, this behavior may not actually
represent a bug (perhaps design limitation would be more
appropriate). An NSDateFormatter can convert from an NSDate to a
string, using the formatting information you specify, and from a
string to an NSDate, but it doesn't store the object value
represented and merge the changes back into the original object.
Given that, it might be possible to have the cell (which does have
the object value available) use the formatter to convert the string
into a date and merge that with the existing date value, but you
would need a specialized cell (not an NSTextFieldCell).
A simpler approach would be to have your model expose separate "day"
and "time" properties that you could bind to for the separate
columns. You could store separate date properties in your entity, or
define getters and setters for each property that extract the
relevant portion of the date property and merge the changes back
into that date property.
In terms of your sample project, you could define a TimeAndDate
class as follows (uses some Obj-C 2.0 features, such as properties
and dot syntax; substitute with ivars, getters/setters, and bracket
notation as needed/desired):
<snip>
For your example application, change your TimeAndDateEntity from
NSManagedObject to TimeAndDate in your data model and bind your
table columns to "day" and "time", respectively.
Thanks for the reply, doing it this way hadn't really occurred to me.
I implemented day and time setters/getters that actually modify and
return portions of the date attribute and it seems to be working
great, thanks! I did change the sort selector for both columns to
"date" so that sorting would work properly as it did before.
-Andrew
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden