相关疑难解决方法(0)

找不到实体的NSManagedObjectModel

这是viewDidLoad中fetchRequest的代码,代码遵循这里的教程,只是我以编程方式链接导航控制器和tableview,而不是使用界面构建器.实体ProductInfo存在.但是,当我运行程序时,我收到错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'ProductInfo''
Run Code Online (Sandbox Code Playgroud)

我已经重置模拟器,因为它是一个旧模型,但错误仍然发生.我也切换到使用FetchedResultsController,但问题仍然存在.问题是因为这些fetchedResultsController方法不在appdelegate中?它们目前位于TableViewController中.我怎么解决这个问题?

viewDidLoad方法:

- (void)viewDidLoad{

NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription * entity = [NSEntityDescription entityForName:@"ProductInfo" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSError * error;
self.productInfos = [_context executeFetchRequest:fetchRequest error:&error];
[fetchRequest release];
[super viewDidLoad];}
Run Code Online (Sandbox Code Playgroud)

ProductInfo.h:

@class ProductDetails;

@interface ProductInfo : NSManagedObject {
@private
}
@property (nonatomic, retain) NSString * productName;
@property (nonatomic, retain) NSString * productPrice;
@property (nonatomic, retain) …
Run Code Online (Sandbox Code Playgroud)

core-data objective-c nsmanagedobject ios

2
推荐指数
1
解决办法
5365
查看次数

标签 统计

core-data ×1

ios ×1

nsmanagedobject ×1

objective-c ×1