2

I am using a CoreDataTableViewController from the Stanford course cs193p, and in my viewWillAppear I call

self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                                                                    managedObjectContext:self.dataBase.managedObjectContext
                                                                      sectionNameKeyPath:nil
                                                                               cacheName:nil];

which on some random occasions makes my app freeze (it doesn't crush, it just freezes). in the CoreDataTableViewController the setter makes a call [self performFetch], which looks like this:

- (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];
}

and the line it get stuck on is

[self.fetchedResultsController performFetch:&error];

any suggestions?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
litov
  • 540
  • 5
  • 16

2 Answers2

1

In my case, i was calling PerformFetch on viewWillAppear method, it has to be call on viewDidLoad() method, even if you are using navigationcontroller. as we know second time onward veiwWillappear method don't get called, in case of calling performseguewithidentifer(push), don't worry for this, fetechresultcontroller get called each time on move-back-next.

hope this may help someone.

Sheshnath
  • 3,293
  • 1
  • 32
  • 60
0

That call will not hang your GUI, because it happens in a background thread. Thus, if your GUI is hanging, it's a different problem.

That being said, you are not supposed to HAVE to call that in normal operation. Normally, you should do one of two things to save changes in a UIManagedDocument:

Use the undo manager, or call

[doc updateChangeCount: UIDocumentChangeDone];
Jody Hagins
  • 27,943
  • 6
  • 58
  • 87
  • you are right. it appears to get stuck when I'm calling [self.navigationController popViewControllerAnimated:YES]; any idease why that would be? – litov Apr 14 '12 at 21:35
  • Step through it in the debugger. – Jody Hagins Apr 14 '12 at 22:12
  • After more examination I was able to narrow down the problem, and completely changed my question. can you pls take another look? – litov Apr 15 '12 at 16:57
  • I don't know why that would hang. If you trace it in the debugger, you may have a chance to at least see what method never returns – Jody Hagins Apr 15 '12 at 19:44