0

I've been searching for a few days, and have continued to learn from reading the apple docs and various tutorials, but there's a problem which I can't seem to get a handle on.

I have a simple app that keeps track of projects, with a single Core Data Entity (ProjectEntry). All the attributes are strings at the moment. It's basically a combination of Paul Hegarty's Core Data lectures and Tim Roadley's web tutorial.

I can add and save Entities and populate a tableview with the data. For the moment, I'm using the CoreDataTableViewController subclass that Hegarty provides in the lecture. I'm mentioning that because...

When my UITableView isn't divided into sections, the new information "instantly" appears in the UI after adding a new entry. However, when I add sections ( via sectionNameKeyPath), the new data still saves, but shows up only after refreshing several times OR waiting 30 seconds before refreshing(via a pull-to-refresh mechanism, which Hegarty also provided).

The tableview delegate methods all seem to be working, as do the NSFetchedResultsController's methods. Using the Stanford/Hegarty CoreDataTableViewController subclass in the past has yielded success, and I've learned a lot reading through the implementation file itself.

The controllers are embedded in a Navigation controller, with the managed object context being passed among the controllers via the prepareForSegue method. Some simple logging shows me the managed object context, initially obtained via a UIManagedDocument, is being successfully passed along.

I've tried the [self.tableview reloadData] and/or the beginUpdates/endUpdates in viewWillAppear, but the delay persists.

What is it about dividing the tableview into sections that's causing the delay? Would calling reloadSections on the tableview be necessary? Like I said, the entries are saved with Core Data and the fetchedResultsController populates the non-sectioned tableview instantly...

It's probably something obvious that I'm just missing, but any help would be appreciated.

vapul
  • 77
  • 8
  • 1
    How are you adding sections. Your symptoms seem to indicate that the data is being saved in another context and eventually flowing into the context bound to the FRC after the UIManagedDoc saves. – Warren Burton Apr 06 '14 at 21:31
  • I'm adding the sections when fetching (initWithFetchRequest), using a string value from the model, plugged into the sectionNameKeyPath part of the above method. What you say is interesting, as the UIManagedDocument is opened/used in the initial view controller (not the tableview). The tableview is a subsequent view controller that uses the managedObjectContext from the UIManagedDoc. I'm still not sure what to do, but you've got me thinking. Thank you! – vapul Apr 06 '14 at 21:41
  • I should mention that the sections are added when the tableviewcontroller calls performFetch, and the initWithFetchRequest is utilized. – vapul Apr 06 '14 at 21:44
  • 1
    We need to see the source code to help you with this one. Specifically what code are you using to add entries to the database and fetch them again when UITableView reloads it's data. – Abhi Beckert Apr 06 '14 at 22:49
  • 1
    Need to see the source code , but another quick idea. Are you using a cache on your FRC. Try using [NSFetchedResultsController initWithFetchRequest....cacheName:nil]; – Warren Burton Apr 07 '14 at 09:28
  • The cache is currently set to nil. I'm going to post code when I get home from work. I had minutes time to try some things out last night, but I think the comment about separate contexts eventually flowing into one another is a step in the right direction. – vapul Apr 07 '14 at 15:31
  • The initial view controller is non-tableview, which can segue to a UIViewController to add a ProjectEntry, or segue to a UITableViewController which lists saved project entries. This initial view controller creates or uses the UIManagedDocument. By setting a one-line check to see if the UIManagedDoc is being used in this initial view controller's viewWillAppear method, the "delay" in displaying new section data in the tableview seems to stop. I'll test it some more before saying the issue is solved. This way, the shared managed object contexts seem better "bound together" via the managed doc. – vapul Apr 08 '14 at 02:56

1 Answers1

0

Warren Burton's comment above made me re-check if my managed object context behavior was consistent while being passed among the view controllers via the prepareForSegue method.

So, as mentioned in my last comment above, it seems to solve the problem for the moment:

from above: The initial view controller is non-tableview, which can segue to a UIViewController to add a ProjectEntry, or segue to a UITableViewController which lists saved project entries. This initial view controller creates or uses the UIManagedDocument. By setting a one-line check to see if the UIManagedDoc is being used in this initial view controller's viewWillAppear method, the "delay" in displaying new section data in the tableview seems to stop. I'll test it some more before saying the issue is solved. This way, the shared managed object contexts seem better "bound together" via the managed doc - vapul

vapul
  • 77
  • 8