I have a People and Pets database with a one-to-many relationship
Character Name Pet <----- → Owner
I use a UITableView supported by Core data, and an nsfetchedresultscontroller to display a list of pets grouped in owner sections.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = [NSEntityDescription entityFromName:@"Pet"
inManagedObjectContext:context]
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Owner.name"
ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *controller = [[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest
managedObjectContext:context
sectionNameKeyPath:@"Owner.name"
cacheName:@"Root"];
This works to display all pets in their owners section, however I also want to display empty sections of people who don't have pets? Is it possible?
Thanks for any help.
source
share