1
我嘗試獲取來自coredata和tableview中顯示與NSFetchResultController工作數據,但給我的錯誤是這樣線程1:EXC_BAD_ACCESS(代碼= 2,地址= 0x7fff5450df68)
線程1:EXC_BAD_ACCESS(代碼= 2,地址= 0x7fff5450df68)目標C
- (NSFetchedResultsController *)fetchResultController {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
_mainContext = [appDelegate manageObjectContext];
if (_fetchResultController != nil) {
return _fetchResultController;
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Student" inManagedObjectContext:_mainContext];
[request setEntity:entity];
//[request setFetchBatchSize:20];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"Student.name" ascending:NO];
[request setSortDescriptors:[NSArray arrayWithObject:sort]];
NSFetchedResultsController *theFetchResultController =[[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:_mainContext sectionNameKeyPath:nil cacheName:@"Root"]; //this point show me error
self.fetchResultController.delegate = theFetchResultController;
return _fetchResultController;
}
請幫助解決這個問題。