当我在 2 个屏幕之间切换几次时,我的 iOS 应用程序挂起。它属于存储数据,但这只是冻结而没有错误。有人知道我该如何解决这个问题吗?
self.fetchF = dispatch_queue_create(label, NULL);
dispatch_async(self.fetchF, ^{
NSArray *feeds = [FeedFetcher getData:self.pageTitle downloadBy:@"up"];
NSManagedObjectContext *newContext = self.managedObject;
for (NSDictionary *feedInfo in feeds) {
[Feed FeedWithInfo:feedInfo InManageObject:newContext];
}
dispatch_async(dispatch_get_main_queue(), ^{
NSError *error = nil;
if (newContext != self.managedObject)
[newContext save:&error];
if (error)
NSLog(@"Error save : %@", error);
[self setupFetchedResultsController];
[self downloadImages:feeds];
});
});
编辑 :
我改变了我的 managedobjectcontext,所以它让每个线程都有一个新线程。但是现在当我在 2 个屏幕之间切换几次时,它会冻结在 [self.fetchedResultsController performFetch:&error]; 没有错误..有人有解决方案的想法吗?
- (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;
if (self.fetchedResultsController != nil)
[self.fetchedResultsController performFetch:&error];
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];
}