2014-06-26 62 views
0

隨着restkit我試圖讓兩個表的數據視圖(收件箱,發),表視圖控制器相同的它們的功能,但它們指的是不同的Web API。 在每個表視圖控制器我配置和初始化restkit並使得用於獲取INBOX或發送的數據的請求時,根據表 一切工作很好,但只具有特定的表中,僅對於另一錯誤發生Restkit獲得不同的數據有兩個表視圖控制器

,其首先被初始化,

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]; 

我在做什麼錯?

+1

我不認爲這與你的tableview有很大關係。可能與映射有關。 – YarGnawh

+0

@YarGnawh正確初始化第二種情況下的restkit? –

回答

1

它未能匹配所有(0)響應描述符

您沒有配置任何響應描述符,或至少沒有將請求URL路徑圖案匹配哪個(大概sent/)和方法(GET )。

檢查描述符註冊和過濾標準(路徑模式,方法和關鍵路徑)。

+0

感謝您的快速響應。但在我的情況下,這一切都取決於我首先打開它是什麼樣的表視圖,那麼應該完成沒有錯誤,但是當我打開另一個表視圖時發生此錯誤,我認爲我的問題是在正確的初始化restkit中這兩種不同的情況 –

+1

你是否在你的代碼中調用過兩次'[[RKObjectManager alloc] init ...'並在任何地方使用'sharedManager'?當然是 – Wain

+0

!我想我開始明白我的錯誤 –

0

解決! 很簡單!

首先,需要在作爲例子的AppDelegate

NSURL *baseURL = [NSURL URLWithString:@"http://api.myhost"]; 
    RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL]; 
    NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil]; 
    RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel]; 
    objectManager.managedObjectStore = managedObjectStore; 
    [RKObjectManager setSharedManager:objectManager]; 
............ 

初始化RESTKit然後當你在視圖控制器需要 作爲例如呼叫你可以使用RESTKit:

RKObjectManager *objectManager = [RKObjectManager sharedManager]; 
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", 
                @"Subject" :@"subject", 
                @"Message" :@"message", 
                }]; 
RKResponseDescriptor *responseDescriptor = 
[RKResponseDescriptor responseDescriptorWithMapping:sentMapping 
              method:RKRequestMethodGET 
             pathPattern:@"/sent/" 
              keyPath:@"results" 
             statusCodes:[NSIndexSet indexSetWithIndex:200]]; 
[objectManager addResponseDescriptor:responseDescriptor]; 
............... 

,並根據需要工作進一步與RESTKit

相關問題