I'm using a NSFetchedResultsController to implement KVO for my UITableView (which is obvious). What I can't figure out is, how to use multiple Entities - sort of a tree structure - to be present(ed) simultaneously.
Here is my setup:
Now I can fetch the data of either to be presented - so far so good. What I want is to have a one-sectioned TableView (like a flattened view) with the following structure:
Though it might look like a thing to be done via sections, it's not. Both Entities should be a UITableViewCells. Can someone please point me the right direction to flatten the without loosing the actual hierarchy.
It sounds like you need to maintain your own 'flattened' datasource. Perhaps the following will work:
When NSFetchedResultController
tells you a new Entity1
has been inserted, you insert Entity1
and its associated Entity2
s into say, _flattenedArray
so it looks like this:
[<Entity1>, <related Entity2>, <related Entity2>...]
Where you insert them is up to you - it pretty much comes down to:
Entity1
and associated Entity2
objects_flattenedArray
to insert the new subarray.reloadData
or some other means to inform the tableView
of the new dataWhen an Entity1
object is removed, remove it and all subsequent Entity2
objects until you encounter the end of _flattenedArray
or run into another Entity1
object. This assumes Entity2
is never a "top level" object. If it is you will need to only remove those Entity2
objects in the relation.
When an Entity1
object gains or loses an Entity2
object, you can first delete the Entity1
object from _flattenedArray
then reinserting it. If this is too efficient, do a merge instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With