nsfetchedresultscontroller with empty sections

Posted by WearyMonkey on Stack Overflow See other posts from Stack Overflow or by WearyMonkey
Published on 2010-04-26T18:25:29Z Indexed on 2010/04/27 17:13 UTC
Read the original article Hit count: 199

Filed under:
|
|

I have a database of People and pets, with a one to many relationship

Person Pet Name Name Pet <----->> Owner

I am using a UITableView backed by Core data and a nsfetchedresultscontroller to display the list of pets, grouped into sections by the owner.

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 under their owners section, however I also want to display the empty sections of People who do not have any pets? Is this possible?

Thanks for any help.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about core-data