- (void)fetchResult
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"Project" ascending:YES];
[request setEntity:self.entityDescription];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
self.fetchResultController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
NSError *fetchError = nil;
BOOL success = [self.fetchResultController performFetch:&fetchError];
if (success) {
NSLog(@"fetched!");
}
else {
NSLog(@"fetch fail!");
}
}
的entityDescription和設置在viewDidLoad方法,因爲它是如下圖所示的背景:核心數據崩潰:的keyPath項目實體未發現
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
self.managedObjectContext = appDelegate.managedObjectContext;
self.entityDescription = [NSEntityDescription entityForName:@"Project" inManagedObjectContext:self.managedObjectContext];
崩潰信息: *終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因是:
可能有人送「的keyPath項目實體沒有發現」手?;)
非常感謝你的回答;)你做出正確的猜測! – JackieLam 2013-05-02 10:35:19