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?
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
companywith 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;
Where the
Keywould be a reference for Core Data to use and display its contents, if required.Where the
Valuewould 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.
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.