【发布时间】:2014-06-26 19:58:15
【问题描述】:
我正在尝试使用 restkit 获取两个表视图(收件箱、已发送)的数据,表视图控制器的功能相同,只是它们引用不同的 web api。 在每个表视图控制器中,我根据表配置和初始化 restkit 并请求获取 INBOX 或 SENT 数据 一切正常,但只有一个特定的表,只有首先初始化的表,否则会发生另一个错误
E restkit.network:RKObjectRequestOperation.m:213 GET 'http://myhost/sent/' (200 OK / 0 objects) [request=0.9469s mapping=0.0000s total=0.9963s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x11001a040 {NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://myhost/sent/', which failed to match all (0) response descriptors:, NSErrorFailingURLStringKey=http://myhost/sent/, NSErrorFailingURLKey=http://myhost/sent/, NSUnderlyingError=0x11007f790 "No mappable object representations were found at the key paths searched.", keyPath=null, NSLocalizedDescription=No response descriptors match the response loaded.
在我的代码中配置restkit:
// initialize RestKit
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
objectManager.managedObjectStore = managedObjectStore;
RKEntityMapping *sentMapping = [RKEntityMapping mappingForEntityForName:@"Sent" inManagedObjectStore:managedObjectStore];
sentMapping .identificationAttributes = @[ @"message_id" ];
[sentMapping addAttributeMappingsFromDictionary:@{
@"objectId":@"message_id",
@"ToUserName":@"email_to",
@"createdAt":@"date_send",
@"Read":@"read"
}];
RKResponseDescriptor *responseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:sentMapping
method:RKRequestMethodGET
pathPattern:@"/sent/"
keyPath:@"results"
statusCodes:[NSIndexSet indexSetWithIndex:200]];
[objectManager addResponseDescriptor:responseDescriptor];
我做错了什么?
【问题讨论】:
-
我认为这与您的 tableview 没有太大关系。可能与映射有关。
-
@YarGnawh 为第二种情况正确初始化 restkit?
标签: ios objective-c restkit