-(void)setupFetchedResultController
{
// 需要获取到一个NSManagedObjectContext
NSManagedObjectContext *context = self.photoprapher.managedObjectContext;
if (context) {
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Photo"];
// 谓语的条件
request.predicate = [NSPredicate predicateWithFormat:@"whoTook = %@", self.photoprapher];
// 排序的条件
request.sortDescriptors = @[[NSSortDescriptor
// 排序元素
sortDescriptorWithKey:@"title"
// 正序还是倒序
ascending:YES
// 排序方式
selector:@selector(localizedStandardCompare:)]];
// 初始化到CoreDataTableViewController里面的fetchedResultsController
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:context
sectionNameKeyPath:nil
cacheName:nil];
}else {
self.fetchedResultsController = nil;
}
}