UItableView sorted by date in sections (and persistence)
I have several HistoryItems which contain an ID, Title and Date. The Date is an NSDate of the exact time it was added to the history down to the second.
At the moment 开发者_如何学编程I just have an NSArray of these objects, the latest HistoryItem added to the end of the NSArray.
How do I make these items display in a UItableView cell in order of date, the latest being in the top, but also each day must have it's own section.
I also need these HistoryItems to be persistent between exit and loading of apps, so should I go with just saving the NSArray to a file, or using CoreData?
Using CoreData will probably be easier since you can use NSFetchedResultsController
to manage the sections 'automatically'. Actually using a NSDate
as a sectionKeyPath can be a bit problematic but as luck has it Apple has some sample code that you should be able to modify from having a section per month to a section per day.
Going with CoreData also gives you the sorting essentially for free.
精彩评论