views:

164

answers:

2

Okay, so I have a UITableView hierarchy. The top level controller is for Categories, which are selected via Fetched Results Controller with no predicate for the Category Entity.

When a user taps a cell, they are advanced to the Items Table View Controller.

At this point, I assumed I should use another fetched results controller with an NSPredicate to filter out the results not matching the selecting category.

However, I've had a lot of difficulty building a predicate that does this. All the examples seem to be for search strings to attribute comparisons. Not comparing a CoreData Relationship.

So is it a better practice to use this method, or simply get the NSSet of items from the passed in Category Managed Object?

+1  A: 

Your second level view controller should have the selected Category set into it via dependency injection as a property. Your second level view controller should only know that "it's" Category is X. It does not need a NSFetchedResultsController at all because you already have all of the information you require via relationships on "it's" Category entity.

To do this, in your top level view controller when a Category is selected you get a pointer to it via the NSFetchedResultsController, instantiate the new view controller, set the Category property and then push the new view controller.

This will give you solid incapsulation and separation between your view controllers.

Marcus S. Zarra
A: 

can you show the code on how to do that? I am new to this. thanks.

S. Kimura