我正在使用斯坦福课程 cs193p 中的 CoreDataTableViewController,并在我的 viewWillAppear 中调用
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.dataBase.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
在某些随机情况下,这会使我的应用程序冻结(它不会崩溃,只会冻结)。在 CoreDataTableViewController 中,setter 调用 [self performFetch],如下所示:
- (void)performFetch
{
if (self.fetchedResultsController) {
if (self.fetchedResultsController.fetchRequest.predicate) {
if (self.debug) NSLog(@"[%@ %@] fetching %@ with predicate: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName, self.fetchedResultsController.fetchRequest.predicate);
} else {
if (self.debug) NSLog(@"[%@ %@] fetching all %@ (i.e., no predicate)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName);
}
NSError *error;
NSLog(@"before");
[self.fetchedResultsController performFetch:&error];
NSLog(@"after");
if (error) NSLog(@"[%@ %@] %@ (%@)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), [error localizedDescription], [error localizedFailureReason]);
} else {
if (self.debug) NSLog(@"[%@ %@] no NSFetchedResultsController (yet?)", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
}
[self.tableView reloadData];
}
它卡住的那条线是
[self.fetchedResultsController performFetch:&error];
有什么建议么?