views:

220

answers:

1

Hi !

I read this post but I don't really understand the code... I have a core data database with an Entity and some attributes. One of them is named "myDate" and has for type NSDate. Now I want to to display each date but eliminate dates with same day-month-year and display them ascendantly .

Have you got an idea?

Thanks a lot !

+1  A: 

If you are looking to have a UITableView with different sections for each date that has events sorted in acceding order then you can: (assuming your myDate attribute has the time as well)

  • create a second date attribute (let's say dateForSection)
  • Override the default setMyDate:
    • set myDate making sure to comply with KVC
    • strip the time from myDate (you will need to use NSCalendar and NSDateComponents)
    • use [self setDateForSection:strippedDate]; to set the secondary date
  • Tell your NSFetchedResultsController to use dateForSection as the sectionNameKeyPath
  • You should then just need to sort the UITableView by myDate (there should be a method for this but I don't have any reference material in front of me right now, it might be in the NSFetchedResultsController as well).
theMikeSwan
Ok thanks for your explanation !
Pierre