I have one table in my core data source which holds some articles with NSDate’s. I basically want to separate the NSManagedObject into days, so you can scroll through and separate articles by date.
What is the best way to approach this? My context is queried out in descending date order, so just need to split that up into days for the UITableView sections, rather than 1 big section.
When you load the data for your table — whether that’s using
NSFetchedResultsControllerand Core Data, or loading a .plist file into anNSDictionaryobject — you can “section” it as you like.You’ll first step through the data (e.g. use the
fetchedObjectsproperty if usingNSFetchedResultsController) and determine what sections you want. Since you’re wanting to split on dates, you might store cutoffs represented byNSDateobjetcts in an array. You would then use this array to implement the variousUITableViewDataSourcemethods: innumberOfSectionsInTableView:you can return thecountof this array, and insectionIndexTitlesForTableView:you can returnNSStringrepresentations of those storedNSDates for the section titles.Methods like
tableView:numberOfRowsInSection:andtableView:cellForRowAtIndexPath:are a little trickier. You’ll probably want to use another “preprocessed” data structure (perhaps a two-level array of arrays, where the inner arrays contain the entity objects you fetched), and you’ll want to set up as the same time as your array ofNSDateobjects.