我知道其他人已经发布了同样的问题,但我无法得到任何答案来解决我的问题。我收到以下错误:
An instance of NSFetchedResultsController requires a non-nil fetchRequest and managedObjectContext
我已包含在我的 appdelegate.m 中:
WorkoutExercisesTVC *workoutExercisesTVC;
workoutExercisesTVC.managedObjectContext = self.managedObjectContext;
workoutExercisesTVC.fetchedResultsController = self.fetchedResultsController;
我在我的表视图控制器类中有:
#import "WorkoutExercisesTVC.h"
@implementation WorkoutExercisesTVC
@synthesize fetchedResultsController = __fetchedResultsController;
@synthesize managedObjectContext = __managedObjectContext;
- (void)setupFetchedResultsController
{
// 1 - Decide what Entity you want
NSString *entityName = @"WorkoutExercise"; // Put your entity name here
NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName);
// 2 - Request that Entity
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
// 3 - Filter it if you want
//request.predicate = [NSPredicate predicateWithFormat:@"enity.name = Blah"];
// 4 - Sort it if you want
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"order"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
// 5 - Fetch it
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
[self performFetch];
}
我的错误发生在步骤 5(获取它)的 setupFetchedResultsController 方法中。
如果有人可以帮助我获得 self.managedObjectContext 使其不再为空,将不胜感激。让我知道您可能需要的其他信息!提前致谢。