The test app I made contains no code except for the value transformer. The 
stuff that is not code is just a Core Data model with one entity called "User", 
with two attributes "name" (string) and "lastLogin" (date).
The IB stuff is just one array controller bound to the app delegate's MOC with 
mode set to Entity and the entity set to "User" and "Prepare Contents" checkbox 
checked. The UI is just a table view with two columns; one column is bound to 
the array controller's arrangedObjects.name and the other column is bound to 
array controller's arrangedObjects.name. Feel free to type in the "Name" and 
"Last Login" headers above the columns just for clarity. Also, there are two 
"Add" and "Remove" buttons that are bound to the array controller in the 
obvious way.
And finally, there is a text field that is bound to array controller's 
selection.lastLogin with a value transformer set to CleanDateTransformer. Here 
is the code for CleanDateTransformer:


#import "CleanDateTransformer.h"

@interface CleanDateTransformer ()- (NSDate *)cleanDateFromDate:(NSDate 
*)aDate;@end

@implementation CleanDateTransformer
+ (Class)transformedValueClass{  return [NSDate class];}
+ (BOOL)allowsReverseTransformation{  return NO;}
- (id)transformedValue:(id)value{   if (value == nil) return nil;    if 
(![value isKindOfClass:[NSDate class]])  {    NSLog(@"invalid class"); 
//running the test app shows that this never gets called anyway    return nil;  
}    return [self cleanDateFromDate:value];}
- (NSDate *)cleanDateFromDate:(NSDate *)aDate{  NSDateComponents *components = 
[[NSCalendar currentCalendar] 
components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit 
fromDate:aDate];    NSDate *cleanDate = [[NSCalendar currentCalendar] 
dateFromComponents:components];    return cleanDate;}
@end




> > Thanks for the tip. However, the value transformer idea did not  
> > work. Even though it ended up showing exactly the same date (the  
> > value transformer just strips the time from the date) for each row,  
> > selecting multiple rows still leaves us with "Multiple values" in  
> > the text field.
> 
> 
>    Might be a good idea to post your code so we know what you tried.
                                          
_________________________________________________________________
Keep your friends updated—even when you’re not signed in.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to