开发者

NSFetchedResultsController Crashes When Navigating from One UITableViewController to Another

In my core data model I have a Person entity that has a "to many" relationship a Course entity (I also have an inverse "to one" relationship from Course to Person).

Now I have a subclassed UITableViewController that uses a NSFetchedResultsController to display Person objects which works fine. I have this set up so that when you click on a Person it publishes another subclassed UITableViewController that uses a NSFetchedController as well to display the Courses associated to the person.

PROBLEM: I get this exception whenever I click on the Person and attempt to display the Course UITableViewController ...

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath name not found in entity <NSSQLEntity Course id=2>'"

Any ideas on how to resolve or troubleshoot?

The code between the two ViewControllers is almost identical except for the NSFetchedResultsController being configured for 开发者_StackOverflow中文版"Person" entities in one and "Course" entities in another


The error means that a keypath, probably a relationship, that you use to define the NSFetchedResultsController does not exist in the data model. These errors often crop up in predicates and sort definitions.

Somewhere you've got a path something like" person.course.someattribute.somerelationship whereas in your model you got person.course.somerelationship. Or you might have simply misspelled something such as a key name.


Do you access the Person object retrieved in the first view controller in the second view controller? If you do, then put a explicit retain in the first executeFetchRequest, like this:

[[[managedObjectContext executeFetchRequest:request error:&error] objectAtIndex:0] retain];

Thats because executeFetchRequest returns autorelease objects. So, you have to retain then. Hope that helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜