iphone SDK: Core Data, how to sort sections in an NSFetchedResultsController?
I have a core data app that is using the sectionNameKeyPath "group.name" with the fetchRequest in order to group the results by the group entity's name attribute. I'm grouping by group.name but I'd like to sort the sections by something other than group.name. According to the NSFetchedResultsController docs:
If the controller generates sections, the first sort descriptor in the array is used to group the objects into sections; its key must either be the same as sectionNameKeyPath or the relative ordering using its key must match that using sectionNameKeyPath.
Which means that the sections must be sorted in the same order the are grouped in. Despite the documentation, prior to iOS 4.2 you could get away without specifying the sectionNameKeyPath as the first sort descriptor which allowed you to sort the sections, but no longer.
What is the best way to sort sections in an NSFetechedResultsController? For example, I want my sections to be grouped by "group.name" but sorted by "group.timestamp".
From the NSFetchedResultsController docs:
You create a subclass of this class if you want to customize the creation of sections and index titles. You override sectionIndexTitleForSectionName: if you want the section index title to be something other than the capitalized first letter of the section name. You override sectionIndexTitles if you want the index titles to be something other than the array created by calling sectionIndexTitleForSectionName: on all the known sections.
链接地址: http://www.djcxy.com/p/36164.html