在我的主控制器上,RESTKIT工作正常:
我的代码和响应描述符如下所示:
// register mappings with the provider using a response descriptor
RKResponseDescriptor *responseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:workOrderMapping
method:RKRequestMethodGET
pathPattern:@"/api/workorder/GetWorkOrderListSimple"
keyPath:nil
statusCodes:nil];
[objectManager addResponseDescriptor:responseDescriptor];
[[RKObjectManager sharedManager] getObjectsAtPath:@"/api/workorder/GetWorkOrderListSimple"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"It Worked");
_workOrders = mappingResult.array;
[self.tableView reloadData];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"error': %@", error);
}];
所以这第一个调用工作正常,但是,在我的第二个控制器上,它似乎以某种方式重用了这个旧的响应描述符,我创建了一个新的响应描述符,但在错误消息中它还引用了GetWorkOrderListSimple,当我明确告诉它使用GetWorkOrderDetail。
RKResponseDescriptor *responseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:workOrderBigMapping
method:RKRequestMethodGET
pathPattern:@"/api/workorder/GetWorkOrderDetail"
keyPath:nil
statusCodes:nil];
但是出于某种原因,这是我的错误信息,有人能指出我正确的调试方向吗?感谢!!!
从网址' http://xxxxxxx.ws/api/workorder/GetWorkOrderDetail?workOrderId=116194'加载了200响应,该响应无法匹配所有(1)响应描述符: http://xxxxxxx.ws pathPattern = / api / workorder / GetWorkOrderListSimple statusCodes =(null)>无法匹配:响应路径' / api / workorder / GetWorkOrderDetail?workOrderId = 116194'与路径模式不匹配' / api / workorder / GetWorkOrderListSimple'。
我有相同的" loading"或"设置"每个视图控制器的Viewdidload中的代码都有两个视图控制器
我在每个Viewdidload中调用configureRestKit,不应该吗?这应该在应用代表或其他地方吗?
我想,因为我在每个视图控制器viewdidload中配置套件,所以每次都是新的
- (void)configureRestKit
{
// initialize AFNetworking HTTPClient
NSURL *baseURL = [NSURL URLWithString:@"http://xxxxxxxx.ws"];
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
// initialize RestKit
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
// setup object mappings
RKObjectMapping *workOrderBigMapping = [RKObjectMapping mappingForClass:[WorkOrderBig class]];
[workOrderBigMapping addAttributeMappingsFromArray:@[@"WorkOrderId", @"Job", @"Address", @"Supervisor", @"PO", @"Priority", @"Status", @"ReceivedDate"]];
RKObjectMapping *workOrderDetailMapping = [RKObjectMapping mappingForClass:[WorkOrderDetail class]];
[workOrderDetailMapping addAttributeMappingsFromArray:@[@"WorkOrderDetailId", @"WorkOrderId", @"WorkOrderProblemId", @"DetailDescription", @"ProductId", @"Qty", @"PONumber", @"Code", @"ProductDescription", @"UOM", @"Price", @"OriginalPrice", @"PctMarkup", @"LineItem", @"OriginalTotal", @"TotalPrice"]];
RKObjectMapping *workOrderProblemMapping = [RKObjectMapping mappingForClass:[WorkOrderProblem class]];
[workOrderProblemMapping addAttributeMappingsFromArray:@[@"WorkOrderId", @"WorkOrderProblemId", @"Description", @"SpanishDescription", @"Action", @"LineItem"]];
//Define Relationships
[workOrderBigMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Details"
toKeyPath:@"Details"
withMapping:workOrderBigMapping]];
[workOrderBigMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Problems"
toKeyPath:@"Problems"
withMapping:workOrderProblemMapping]];
// register mappings with the provider using a response descriptor
RKResponseDescriptor *responseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:workOrderBigMapping
method:RKRequestMethodGET
pathPattern:@"/api/workorder/GetWorkOrderDetail"
keyPath:@"/api/workorder/GetWorkOrderDetail"
statusCodes:nil];
[objectManager addResponseDescriptor:responseDescriptor];
- (void)loadWorkOrders
{
NSString *WorkOrderId = [NSString stringWithFormat:@"%i", _workOrderId];
NSMutableDictionary *params =[[NSMutableDictionary alloc] init];
[params setValue:WorkOrderId forKey:@"workOrderId"];
[[RKObjectManager sharedManager] getObjectsAtPath:@"/api/workorder/GetWorkOrderDetail"
parameters:params
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"It Worked");
_workOrders = mappingResult.array;
//paint screen
WorkOrderBig *mainWorkOrder = [_workOrders objectAtIndex:0];
self.lblWorkOrderId.text = mainWorkOrder.WorkOrderId;
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"What do you mean by 'there is no coffee?': %@", error);
}];
}
答案 0 :(得分:0)
我在每个Viewdidload中调用configureRestKit,不应该吗?
根据您的配置,是的,您应该
这应该在app委托中还是在其他地方?
不,应用程序委托用于应用程序级事件管理,而不是数据配置
因此,您的配置几乎没问题,问题在于您的用法:[RKObjectManager sharedManager]
。当您致电sharedManager
时,您将始终返回已创建的第一个对象管理器 - 而不是本地'创建
您应该在每个视图控制器上使用@property
来存储他们创建的objectManager
,然后使用self.objectManager
代替[RKObjectManager sharedManager]
。