One-to-Many NSFetchedResultsController with as much rows as the relationship NSSet contains

BossBols

I'm trying to set up a tableView like so:

-Family
--Person 1
--Person 2
--Person 3
-Family 2
--Person 1
--Person 2
--Person 3
-Family 3
... etc

I have no problems getting the sections populated with the family names:

- (NSFetchedResultsController *)fetchedResultsController:(NSString *)forEntity sortyBy:(NSString*)sortAttribute sectionName:(NSString *)sectionName {

if (fetchedResultsController != nil) {
    return fetchedResultsController;
}

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:forEntity inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:sortAttribute ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:20];

NSFetchedResultsController *theFetchedResultsController = 
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[self managedObjectContext] sectionNameKeyPath:sectionName cacheName:nil];

self.fetchedResultsController = theFetchedResultsController;
self.fetchedResultsController.delegate = self;
return fetchedResultsController;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [self.fetchedResultsController.fetchedObjects count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{
id <NSFetchedResultsSectionInfo> sectionInfo = self.fetchedResultsController.sections[section];
return [[[sectionInfo objects] objectAtIndex:0] name];
}

However filling in the rows containing the persons is proving difficult for some reason.

There is a One-to-many relationship active that provides Family with an NSSet attribute called "Persons".

How can I return a correct count on the number of persons in that set and then set the cells accordingly with the Persons' data?

I tried altering the numberOfRowsInSection method in numerous ways but can't seem to find a non-crashing way of accessing the Family. Persons NSSet here to count them.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
id <NSFetchedResultsSectionInfo> sectionInfo = self.fetchedResultsController.sections[section];
return [sectionInfo numberOfObjects];

}

Should I be using something other than an NSSet or even NSFetchedResultsController in a whole?

Important is that I will place "2 segmentedControls" above the tableView. This will allow some deep filtering but for that to work I need to be able to fill sections and corresponding rows depending on what the user selects to filter on.

For example:
SegCtrl 1: User selects Family, SegCtrl 2: User selects age.
This draws a UITableView with the available Family names as sections and as rows all the ages of the Persons in that Family.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

One to many relationship with NSfetchedresultscontroller

From Dev

CoreData :NSFetchedResultsController one to many to many to many relationship

From Dev

iOS core data one to many relationship NSSET

From Dev

core data one to many relationship, assign, fetch, predicate on NSSet

From Dev

IOS/Objective-C/CoreData: Editing NSSet in One-to-many relationship

From Dev

Get rows with only one reference in many-to-many relationship

From Dev

Combine multiple rows to one (many-many relationship)

From Dev

Core-Data NSFetchedResultsController to-many relationship

From Dev

Core-Data NSFetchedResultsController to-many relationship

From Dev

In one to many relationship, return distinct rows based on MIN value

From Dev

mysql join one to many relationship and print in different rows

From Dev

sorting data of type NSSet of a to-many relationship using NSSortDescriptor

From Dev

How to apply NSSortdiscriptor or NSPredicate on a NSSet of a to-many relationship

From Dev

One To Many Relationship In Firebase

From Dev

Doctrine One to Many relationship

From Dev

Seeding one to many relationship

From Dev

Themeing a one to many relationship

From Dev

One to many relationship table

From Dev

Paginate a One to Many Relationship

From Dev

Laravel: one to many relationship

From Dev

Accessing a one to many relationship

From Dev

Displaying one to many relationship

From Dev

Implementing one to many relationship

From Dev

MagicalRecord: one to many relationship

From Dev

Paginate a One to Many Relationship

From Dev

Seeding one to many relationship

From Dev

one to many relationship in laravel

From Dev

EntityFramework - One to many relationship

From Dev

One to many relationship in springboot

Related Related

HotTag

Archive