Reputation: 632
I have a core data model with multiple entities, each entity corresponds to a view controller were the user inserts information for each entity, for example:
Tire(first Entity) - Type(first atribute), cost(second atribute). Glass(second Entity) - Color(first atribute), size(second atribute), cost(third atribute).
For each entity i have a MVC with textfields were the user inserts information for each entity, so if you press tire button, you insert a type of tire, cost.. and so on for the other entities.
Everything goes well when i pull just one entity, i insert the information in the textfields then press save, and it appears on my tableview nicely!. But, as you already know, i want the rest of the entities inserted in my tableview and in different sections.
I´ve tried "messing" with the "cellForRowAtIndexPath", also in my "fetchedResultsController" method´s with "if´s" and "swich´s" but with no success. What am i missing here?!?!?!
Thanks, and sorry for my english.
Upvotes: 2
Views: 862
Reputation: 80271
You need a single entity to have your NSFetchedResultsController
work properly and take advantage of its advanced memory and performance features.
So modify your data model and make one new entity, Item
that is an abstract parent entity of the other entities. (You can assign parent entities in the model editor.) Make sure that the attributes that are shared by all the items (e.g. a name) belong to the parent. These should be the attributes that you want to display in your table view.
Now you could add an NSString
or NSNumber
attribute type
unique for each sub-entity and easily sort by this key in your NSFetchedResultsController
.
From Apple's [Core Data Programming guide][1] :
If you define an entity inheritance hierarchy (see “Entity Inheritance”), when you specify a super-entity as the entity for a fetch request, the request returns all matching instances of the super-entity and of sub-entities. In some applications, you might specify a super-entity as being abstract (see “Abstract Entities”). To fetch matching instances of all concrete sub-entities of the abstract entity, you set the entity for fetch specification to be the abstract entity. In the case of the domain described in “Abstract Entities,” if you specify a fetch request with the Graphic entity, the fetch returns matching instances of Circle, TextArea, and Line.
So you fetch all Items
, sort by type
, and for each cell you determine the type and fill your text labels with the appropriate properties.
Upvotes: 5