1

你好,

我正在使用 aRKFetchedResultsTableController来从我的 WS 中获取数据并驱动我的 tableview。

RKTableViewCellMapping用来映射我的模型和单元格。

这是我设置 cellMapping 的方法:

RKTableViewCellMapping *cellMapping = [RKTableViewCellMapping cellMapping];
cellMapping.cellClassName = @"CrudCategoryCell";
cellMapping.reuseIdentifier = @"CrudCategory";
cellMapping.rowHeight = 100; 
[cellMapping mapKeyPath:@"name.name" toAttribute:@"nameLabel.text"];
[cellMapping mapKeyPath:@"desc.desc" toAttribute:@"descLabel.text"];

[self.tableController mapObjectsWithClass:[CrudCategory class]            
                      toTableCellsWithMapping:cellMapping];

如您所见,我的模型由一个类 : 表示CrudCategory

这个类有两个属性:name, desc; 分别为CrudCategoryNameCrudCategoryDesc

这些类继承自NSManagedObject.

运行应用程序时:

Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Cannot build a tableView cell for object <NSManagedObject: 0x6c4fb90> 
(entity: CrudCategory; id: 0x6c4d900 <x-coredata://FA7323F8-519D-4AA9-AC6E-  BD30446B4C9B/CrudCategory/p210> ; data: <fault>): 
No cell mapping defined for objects of type 'NSManagedObject''

我能够通过使用使其工作:

[self.tableController mapObjectsWithClass:[NSManagedObject class]
                      toTableCellsWithMapping:cellMapping];

代替 :

[self.tableController mapObjectsWithClass:[CrudCategory class]
                      toTableCellsWithMapping:cellMapping];

我真正不明白的是,异常声明没有类型对象的映射NSManagedObject,当我使用NSManagedObject类而不是CrudCategory- 它只是继承自NSManagedObject- 一切都很好......

这是我的环境:

  • ios5
  • RestKit(github 中的最后一个稳定版本)
  • 故事板

如果有人有想法:)

谢谢 !

编辑 - 已解决: 我通过为每个实体指定适当的类来解决数据模型中的这个问题。

4

1 回答 1

0

Your CrudCategory class must have properties associated in it with the coredata model you have. Also you must be using this class to define mapping for the restkit mapping provider.

When you just use NSManagedObject class youre using a superclass which does not define the attributes in the subclass CrudCategory hence you see the issue. (I think!)

The question is, why do you want to use NSManagedObject Class instead of CrudCategory? Using CrudCategory is the right way of doing this as I use a similar method in my app + it is the method that Restkit exampls RKGithub uses.

于 2012-05-25T11:57:34.617 回答