Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4257604
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:32:05+00:00 2026-05-21T05:32:05+00:00

I’ve looked through many posts and still not sure how to resolve this. Hope

  • 0

I’ve looked through many posts and still not sure how to resolve this. Hope someone can help.

It works until hitting the last data source method, cellForRow.
At that point I can get the correct NSSet for each section, but unordered. How does intropection into the relationship properties work for the rows?

using a string literal in the cellForRow I do get the correct number of rows in each section, but obviously no connection to the managed objects that would be there.

How can I populate the rows from the NSSet relationship? All insight appreciated

Category<<—>>Person
cName ———- pName

relationships
people ———- categories

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [[self.fetchedResultsController fetchedObjects] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section     {
Category* cat = [[self.fetchedResultsController fetchedObjects] objectAtIndex:section];
return [[cat people] count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
Category* cat = [[self.fetchedResultsController fetchedObjects] objectAtIndex:section];
NSNumber *rowCount = [NSNumber numberWithUnsignedInteger:[[cat people] count]]; 
return cat.cName;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
NSManagedObject *mo = [[fetchedResultsController fetchedObjects] objectAtIndex:index.row]];

// returns the correct set but unordered, possibly work with this to populate the rows?
//NSSet *theSet = [[NSSet alloc] initWithSet: [mo valueForKeyPath:@"people.pName"]];

// doesn't work
// cell.textLabel.text = [NSString stringWithFormat:@"%@",[mo valueForKeyPath:@"people.pName"]];

cell.textLabel.text = @"something";
return cell;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:32:06+00:00Added an answer on May 21, 2026 at 5:32 am

    Your problem is that you are fetching Category objects but you are trying to set your rows with Person objects. The Person objects are unordered because they are not the fetched objects. They have no relationship to the logical structure of the tableview. In fact, they can’t because they have a to-many relationship with Category such that the same Person object can show up in many times in the same table.

    The best solution is to decompose this into two hierarchal tables. One displays the Category list and the second displays the Person objects in the people relationship of the Category object chosen in the first tableview.

    You can attempt to get it working with the current design by trying something like:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
        Category *sectionCategory=[[fetchedResultsController fetchedObjects] objectAtIndex:indexPath.section];
        NSSortDescriptor *sort=[NSSortDescriptor sortWithKey:@"pname" ascending:NO];
        NSArray *sortedPersons=[sectionCategory.people sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
        Person *rowPerson=[sortedPersons objectAtIndex:indexPath.row];
        cell.textLabel.text = rowPerson.pname;
    

    This will work if your data is static. If it changes while the table displays, you will have trouble. It will have a bit of overhead because you have to fetch and sort all the Person objects of the sectionCategory object each time you populate a row.

    I strongly recommend a two tableview solution. That is the preferred solution for hierarchal data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.