How to use NSDateFormatter with NSPopUpButton

313 views Asked by At

I have an NSPopUpButton's content bound to an Array Controller of "Meeting" entities and it's content value bound to the same array controller, but to the "date" model key path. Everything works fine. But I'd like to format the way the date is displayed with an NSDateFormatter and I can't get it to work. Any hints? Is it even possible?

1

There are 1 answers

0
Johannes Fahrenkrug On BEST ANSWER

OK, some guys on Twitter suggested adding a formattedDate method to my model. I knew from the get go that I could do that but was hoping that there's some IB-only solution. I don't think there is, so to answer my own question: NSDateFormatter doesn't (seem to) work with NSPopUpButton.

My formattedDate method looks like this:

- (NSString *)formattedDate {
  return [NSDateFormatter localizedStringFromDate:self.date dateStyle:NSDateFormatterLongStyle timeStyle:NSDateFormatterNoStyle];
}