appdelegate
passes modelview
to each tab controller
|
|
/ \
/ \
/ \
/ \
/ \
/ \
vc1 vc2
show list show grouped
of years table with years
| as headers and
| courses within
vc3 each year
list courses
in selected
year
|
|
add new
course to
selected
year
In both vc1 and vc2, the entity that I am reading from my core data model is "years". In the "numberOfRowsInSection()", etc routines, I access the courses through "to-many" relationships in my model, via NSSet(). (i.e. courses_rel). All this works fine for the initial display of both views.
vc3 also works great. The user can add a new course to any selected year.
Here is my problem. When the user adds a new course via vc3, then switches over to vc2, the new course does not show up and I get the error provided below. I know that I'm getting the error because the change was made in the courses database table but the tableview in vc2 is being loaded from the "years" table. It never gets the "didChangeObject" and other relevant messages since it is dealing with "years" and not courses. However, the body of each grouped section is a list of courses!
How do I get a change in courses table (vc3) to be reflected immediately when the user goes to vc2?
I have placed a new fetch operation and a [view reloadData] in the viewWillLoad function but again, it is a fetch of years and not courses so it has no effect.
Here is the error I get when the user switches over to vc2 after adding a course in vc3.
CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)