• 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
NSDateFormatter and NSCell oddness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSDateFormatter and NSCell oddness


  • Subject: NSDateFormatter and NSCell oddness
  • From: email@hidden
  • Date: Wed, 9 Jul 2008 01:43:17 +0100

Hello,

I'm trying to replicate the Finder's behaviour for date fields when resizing. I found this on the archives which pretty much has the answer:

http://www.cocoabuilder.com/archive/message/cocoa/2005/8/9/143911

I'm trying to update it so that it returns the correct value for the current localisation. This is the full code of my NSCell subclass (debugging commented out):

@implementation DMSquishableDateCell

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
{
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; // needed?

int width = cellFrame.size.width;


    if (width < 130)
        [dateFormatter setDateStyle:NSDateFormatterShortStyle];
    else if (width < 145)
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    else // if (width < 170)
        [dateFormatter setDateStyle:NSDateFormatterLongStyle];

	[dateFormatter setTimeStyle:NSDateFormatterNoStyle];

    [self setFormatter:dateFormatter];
    [super drawWithFrame:cellFrame inView:controlView];

//NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate: 118800];
//NSLog(@"formatted date: %@", [dateFormatter stringFromDate:date]);

// if ([self hasValidObjectValue])
// NSLog(@"formatted date: %@", [dateFormatter stringFromDate:[self objectValue]]);
}


@end

In my awakeFromNib: method where the table is created, I set the cell thusly:

DMSquishableDateCell *dateCell = [[[DMSquishableDateCell alloc] init] autorelease];
NSTableColumn *creationDateColumn = [table tableColumnWithIdentifier:@"creation_date"];
[creationDateColumn setDataCell:dateCell];


However, the column is completely blank. If I remove the three lines above, the dates are properly displayed. The lines that I've commented above verify that the formatter itself is working properly. The cell objects come straight from CoreData, and seem to be objects of class "__NSCFDate".

What am I doing wrong?!?

Thanks!

Demitri

_______________________________________________

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


  • Follow-Ups:
    • Re: NSDateFormatter and NSCell oddness
      • From: Nathan Kinsinger <email@hidden>
  • Prev by Date: Re: How to support dictionary service in a custom text view?
  • Next by Date: Importing Xcode 2.x projects into Xcode 3
  • Previous by thread: Re: Distributed Objects "connection went invalid while waiting for a reply"
  • Next by thread: Re: NSDateFormatter and NSCell oddness
  • Index(es):
    • Date
    • Thread