2012-09-25 3 views
0

블록이있는 객체를 게시하려고합니다. OnDidFailWithError 결코 부르지 않았고 폭발했다.Restkit onDidFailWithError가 호출되지 않습니다.

이 내가 가진 오류입니다 : 여기

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[MyClass objectLoader:didFailWithError:]: unrecognized selector sent to class

는 그리고 나의 코드 :

[[RKObjectManager sharedManager] postObject: myObj usingBlock:^(RKObjectLoader *loader){ 
    loader.targetObject = nil; 
    loader.delegate = (id)self; 
    loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[MyClass class]]; 

    loader.onDidFailWithError = ^(NSError *error) { 
     NSLog(@"Error %@", [error localizedDescription]); 
    }; 

    loader.onDidLoadObject = ^(id obj) { 
     NSLog(@"Comment"); 
     NSLog(@"%@",obj); 
    }; 

    loader.onDidLoadResponse = ^(RKResponse *response) { 
     NSLog(@"Response: %@", [response bodyAsString]); 
    }; 

    loader.onDidLoadObjects=^(NSArray* objects){ 
     //post notification 
     [[NSNotificationCenter defaultCenter] postNotificationName:@"finish" object:nil]; 
    }; 

    loader.serializationMIMEType = RKMIMETypeJSON; // We want to send this request as JSON 
    loader.method = RKRequestMethodPOST; 

    loader.serializationMapping = [RKObjectMapping serializationMappingUsingBlock:^(RKObjectMapping* mapping) { 
     [mapping mapAttributes:@"field1", @"field2",nil]; 
    }]; 
}]; 

답변

0

오류를 처리 할 수없는 경우에 이것을 시도 onDidLoadResponse

loader.onDidLoadResponse = ^(RKResponse *response) { 

     NSLog(@"Response did arrive"); 
     if([response statusCode]>299){ 

      NSError *error = nil; 
      id parsedResponse = [NSJSONSerialization JSONObjectWithData:[response body] options:NSJSONWritingPrettyPrinted error:&error]; 
      NSLog(@"%@",parsedResponse); 

     } 

    }; 
+0

Myclass는 온라인에서 공개하고 싶지 않은 클래스의 이름입니다. 내가 성공을로드 개체를 가지고 있지만 단지 오류를 처리 할 수 ​​없습니다. – user1688346

+0

방금 ​​답을 편집했는데 문제가 무엇인지 디버그하는 데 도움이되는지 확인하십시오. – clopez

0

대리인을 self로 설정합니다.이 restKit dele를 호출합니다. 현재 컨트롤러의 게이트 메서드를 만들고 만든 블록을 사용하지 마십시오.

관련 문제