“NSFetchedResultsController”代码上的“NSRangeException”问题

时间:2014-01-05 14:05:32

标签: ios nsfetchedresultscontroller nsfetchrequest nsrangeexception

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

以下代码中存在错误;行:

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

原因是; 由于未捕获的异常'NSRangeException'而终止应用,原因:' - [NSPathStore2 characterAtIndex:]:index(6)超出边界(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;

}

感谢您的帮助, 即

0 个答案:

没有答案