NSFetchedResultsController and child UITableViewController
Right now I have an UITableViewController
that displays a set of Artist
objects sorted into sections (alphabetically) using NSFetchedResultsController
. When you tap an artist in that list, a second UITableV开发者_如何转开发iewController
is pushed and displays the artist.shows
objects, also sorted into sections (by date).
Right now I'm sorting that second data source (artist.shows) "manually", using NSSortDescriptor
and a for()
loop to determine where to have the table view sections (one section for every month).
Is that the right way to go? Would it make more sense to create a second NSFetchedResultsController
to sort that data, although it would basically be fetching data I already have in artist.shows
?
You should definitely use a second fetched results controller. It can share the managedObjectContext with the first, allowing to access the already faulted objects in that context.
You'll want to structure your predicate / sort descriptor for the controller appropriately, such as:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"artist.name == %@" argumentsArray:[NSArray arrayWithObject:selectedArtist.name]];
You could also scope it by the actual artist object but that should give you the idea.
精彩评论