Nsfetchedresultscontroller with empty partitions

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.

+3
source share
3 answers

. . UITableView, Core Data.

+1

NSFetchedResultsController, , , - TAFetchedResultsController.

: https://github.com/timothyarmes/TAFetchedResultsController

+1

If there is only 1 section, it is quite easy to get around the problem of displaying the header of a UITableView header when there are no sections.

0
source

Source: https://habr.com/ru/post/1742874/


All Articles