Reputation: 3948
Here's my structure:
I have an Entity called Element. And Element contains multiple Time Stamps. Time Stamp is an Entity with a relationship to element.
Element
Time Stamp 1
Time Stamp 2
Time Stamp 3,
...,
...
My View Controllers and Table View are:
View Controller A
TableView A // <- displays elements
View Controller B
TableView B // <- should display all timestamps from a given element
What I'm trying to do:
I can get my "Element" in View Controller A, and pass it along to View Controller B, like this:
Element *anElement = [_fetchedResultsController objectAtIndexPath:indexPath];
ViewControllerB *vc = (ViewControllerB *)[[self storyboard]instantiateViewControllerWithIdentifier:@"ViewControllerB"];
vc.element = anElement;
Now, on my View Controller B I have a fetchedResultsController that feeds my Table View B. I need this fetchedResultsController show all the Time Stamps from the passed Element object.
How can I do this?
I know I could fix this, by adding a unique date property to Element, so that I could have a predicate in my View Controller B that matched that unique date. However, if posible, I rather not do that. I find it hard to believe that I need to have my Core Data Entity to have a dependency on what I need to do in my View Controllers.
Thank you!
Upvotes: 0
Views: 55
Reputation: 13296
You should be able to user the following predicate with your fetchedResultsController to get the TimeStamp objects.
[NSPredicate predicateWithFormat:@"element == %@", self.element];
Upvotes: 1
Reputation: 8608
If Time stamp is an NSSet you could just pass that along to ViewController B and do away with the fetchedResultsController in B.
Or instead of assigning the entity as done in above, pass along the NSManagedObjectID to ViewController B and do a fetch based on that. This would be a better way of doing if you want to use a fetch controller in B.
Upvotes: 0