'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name

落爺英雄遲暮 提交于 2019-12-23 23:58:43

问题


I have a window based applicaiton with tab bar and navigation bar integrated into it. On the navigation bar have a custom button which opens a table view.

On clicking on the cell of the table I want to open a new table view controller. But as soon as I click on the cell of first table I get an exception that

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'AddForm''

I have checked that AddForm is in right place.

I have tried all the solutions given above and on other thread, but still stuck. I hope someone can help me.

The flow is something like this

ListButton (on click opens a list view) -> a table view opens -> (on click of a cell should open a new table view Controller and fetch data from core data)

My root view controller code is in the second table view controller file... is that what I am doing wrong? I am doing so because I don't need the core data before that....

Please help

Thanks in advance


回答1:


I Used to have the same problem first of all check in your AppDelegate.m class if the managedObjectContext is created

if it is created check if it is pass it as argument something like this

 MasterViewController *controller = (MasterViewController *)masterNavigationController.topViewController;
    controller.managedObjectContext = self.managedObjectContext;

if that is correct for you main view just be sure that you are passing it through your views something like this

self.detailViewController.managedObjectContext = self.managedObjectContext;

well at least that works for me =)




回答2:


The most common cause of this problem is misspelling the name of the entity or getting the capitalization wrong. Check that AddForm is spelled exactly the same in the code and the data model editor.



来源:https://stackoverflow.com/questions/4252828/nsinternalinconsistencyexception-reason-entityforname-could-not-locate-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!