简体   繁体   中英

NSDateFormatter in View based NSTableView

I can't figure out how to set an NSDateFormatter for a static text table cell view in Interface Builder using the new view based NSTableViews . Since the problem is Interface Builder related, here are the steps to recreate the setup in Interface Builder:

  1. Create Table View
  2. Change Content Mode to View Based , name one column Date and have it contain static text views.
  3. Fill the table with some test data (one column should contain dates)
  4. Create a NSDateFormatter , in settings, set the Date Style to Short Style
  5. Open the Static Text View for our date and set the formatter to the NSDateFormatter .

I seem to always get the default date formatting. How do I apply the date format to the dates in the table?

The solution was actually very simple with the latest XCode 4.3.1:

  • In Interface Builder, drag a Date Formatter into the target cell (so it becomes it's child)
  • Set the date format for the Date Formatter

No additional wiring was required. Hope this helps somebody else running into this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM