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 3806160
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:47:29+00:00 2026-05-19T14:47:29+00:00

I have a Company entity with about 20 fields and I’m wanting to use

  • 0

I have a Company entity with about 20 fields and I’m wanting to use a grouped tableView with manually created section headers (ie: General, Financial, Misc.), but I am unsure of how to make Core Data understand how to treat these section headers and make them relate only to the data I want to show in these groups.

For example, name, logo, etc would go under General, budgets, cash would go under financial, etc.

Basically, I want to control what data from Core data gets put into each category and display it.

In the Core books sample there is this code:

/*
 The data source methods are handled primarily by the fetch results controller
 */

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


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}

But how do I make it understand that the sections aren’t in Core data, but created manually?

  • 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-19T14:47:30+00:00Added an answer on May 19, 2026 at 2:47 pm

    I’ve got an answer to my problem now, I do not know if its the correct approach, but it is working and would welcome comments.

    Just to clarify what the problem was, and what I was trying to do.

    I have a core data entity company with about 10 or so fields inside them, however rather than listing them all in one go, I wanted to group the outputted fields.

    For example, I have about 6 fields relating to cash such as “cash”, “marketingBudget”, “seoBudget”, etc and I wanted to group this data on the tableView, but the problem was I didn’t know how to set up a relationship so that table.field.x belonged to group.x, and so on.

    The answer I came to was to use a PLIST/dictionary that pretty much mirrors the structure of the core data entity; and assign the structure to the groups I want to display.

    My dictionary looks like this;

    (root)

    ->CompanyTpl (array)

    –> Item 0 (Dictionary)

    —> Section (String) = “General”

    —> Children (Array
    )
    ——> Item 0 (Dictionary)

    ———-> Key = “name”

    ———-> Value = “Company Name” …

    Where the Key would be a reference for Core Data to use and display its contents, if required.

    Where the Value would be would to display at the cellForRowAtIndexPath.

    So, in my code I basically went through the section (by which I mean tableView section) and then find the correlating children info from the PLIST; and get the Key/Value and use this as and when required.

    Here is a cut down version of the code.

    - (void)viewDidLoad {
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"CompanyTpl" ofType:@"plist"];
        self.companyDictionary = [[NSDictionary dictionaryWithContentsOfFile:plistPath] retain];
    
        // self.tableDataSource is a NSMutableArray
        self.tableDataSource = [self.companyDictionary objectForKey:@"CompanyTpl"];
    
        // Debugging info
        NSLog(@"Section = 0");
    
        NSLog(@"%@", [self.tableDataSource objectAtIndex:0]);
    
        NSLog(@"Section Name = %@", [[self.tableDataSource objectAtIndex:0] objectForKey:@"Section"]);
    
    
        NSArray *sectionChildren = [[self.tableDataSource objectAtIndex:0] objectForKey:@"Data"];
    
        NSLog(@"Section Children = %@", sectionChildren);
        NSLog(@"Count of Section Children = %d", [sectionChildren count]);
    
    
    }
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return ([self.tableDataSource count]);
    }
    
    // Section header
    -(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
        NSString *title = nil;
    
        title = [[self.tableDataSource objectAtIndex:section] objectForKey:@"Section"];
    
        return title;
    }
    
    
    // Customize the number of rows in the table view.
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    {
    NSInteger rows = 0;
    
        NSArray *sectionChildren = [[self.tableDataSource objectAtIndex:section] objectForKey:@"Data"];
    
        NSLog(@"Section Children = %@", sectionChildren);
        NSLog(@"Count of Section Children = %d", [sectionChildren count]);
    
        rows = [sectionChildren count];
    
    
        return rows;
    }
    
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView 
             cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
    
        NSArray *sectionChildren            = [[self.tableDataSource objectAtIndex:indexPath.section] objectForKey:@"Data"];
        NSDictionary *sectionChildrenData   = [sectionChildren objectAtIndex:indexPath.row];
    
        //NSLog(@"Section Children data = %@", sectionChildrenData);
    
        NSString *scKey     = [sectionChildrenData objectForKey:@"Key"];
        NSString *scValue   = [sectionChildrenData objectForKey:@"Value"];
    
        NSLog(@"scKey = %@", scKey);
    
        // Grab the data from Core Data using the scKey
    
    
    
        static NSString *CellIdentifier = @"defaultCell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    
    
            //cell.textLabel.text = @"test";
    
            cell.textLabel.text = scValue;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
        }
        return cell;
    }
    

    The idea would be that I can use the KEY when referencing Core Data to grab its contents and display it on the tableView controller at cellForRowAtIndexPath cell.textLabel.text value.

    One could go a little further in depth and have more info in the PLIST such as what the subtitle should be, etc.

    Anyway, would welcome comments and thoughts.

    Thanks.

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

Sidebar

Related Questions

Assuming I have an Entity Framework 4.2 class like this: class Company { public
I have many to one relation, let's say User has a Company. Company entity
I have been reading about entity framework over the past couple of days and
If I have a company entity, with a one to many association to user
I have a persistent entity that I'm using as a template: Company Locations Departments
I have created a custom entity in MS CRM 4.0 and am trying to
Say we have a entity Company that has a to-many relationship to the Employee
I have an entity like this: public class Employment { public virtual Company Company
I have an company asp.net website with textboxes which may contain several hundred words.
I have my company logo appearing in the footer of my site, when the

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.