0

我正在研究 fetchResultsController 并使用教程对我的代码进行必要的更改。

下面的代码有错误;线:

[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];

原因是;由于未捕获的异常“NSRangeException”而终止应用程序,原因:“ -[NSPathStore2 characterAtIndex:]: index (6) beyond bounds (2)”

你能帮我解决这个问题吗?

- (NSFetchedResultsController *)fetchedResultsController {

if (_fetchedResultsController != nil) {
    return _fetchedResultsController;
}

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
                               entityForName:@"AnswerQuestionDetails" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

//NSSortDescriptor *sort = [[NSSortDescriptor alloc]
 //                         initWithKey:@"aqDt.ID" ascending:NO];
//[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

[fetchRequest setFetchBatchSize:20];

NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
_fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;

return _fetchedResultsController;

}

谢谢你的帮助,E。

4

0 回答 0