Use one NSManagedObject section for a UITableView and does this relate to another NSManagedObject for rows?

Is it possible to set a UITableView with NSFetchedResultsController as a dataSource where the Contact Group defines the sections, and the Contact Group to-many relationship with Person defines the rows for each section?

So my data model looks like this.

 Contact Group - Person - Person - Person Contact Group - Person - Person - Person 

Contact Group is one NSManagedObject and has a to-many relationship with Person NSManagedObjects . In principle, the table view should look the same as above.

I use MagicalRecord, if that matters, does it look right?

 - (NSFetchedResultsController *)fetchedResultsController { if (!_fetchedResultsController) { _fetchedResultsController = [ContactGroup fetchAllSortedBy:@"displayOrder" ascending:YES withPredicate:nil groupBy:@"SELF.contacts" delegate:self]; } return _fetchedResultsController; } 

Oh, and I need to be able to sort (and save) contacts in each section.

Any guidance is appreciated. Please feel free to comment if I need to clarify better.

+4
source share
1 answer

I have no experience with Magical Record, but since you mainly want records from Person, you have to call this method for Person, not ContactGroup:

 - (NSFetchedResultsController *)fetchedResultsController { if (!_fetchedResultsController) { _fetchedResultsController = [Person fetchAllSortedBy:@"displayOrder" ascending:YES withPredicate:nil groupBy:@"contactGroup.groupName" delegate:self]; } return _fetchedResultsController; } 
+1
source

All Articles