我正在使用 RestKit 将数据映射到两个类(区域和类别)中的属性,以便在两个表视图(区域和类别)中使用。但是,它似乎只是为我在测试应用程序时进入的第一个视图正确映射数据。例如,当我首先查看类别,然后切换区域时,我的区域将存储为类别类型的对象。如果我先查看区域,然后查看类别,我的类别将被映射为区域类型的对象。由于对象的数量,我可以说正在检索正确的信息,但它没有被存储为正确的类型。如何确保每个映射请求都正确完成?每个映射的代码如下:
分类:
RKURL *baseURL = [RKURL URLWithBaseURLString:@"MyUrl"];
RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
objectManager.client.baseURL = baseURL;
RKObjectMapping *categoryMapping = [RKObjectMapping mappingForClass:[Category class]];
[categoryMapping mapKeyPathsToAttributes:@"categoryID", @"categoryID", @"parentID", @"parentID", @"categoryName", @"categoryName", @"childrenCount", @"childrenCount", @"parentCount", @"parentCount", @"catCount", @"catCount", nil];
[objectManager.mappingProvider setMapping:categoryMapping forKeyPath:@""];
地区:
RKURL *baseURL = [RKURL URLWithBaseURLString:@"MyUrl"];
RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
objectManager.client.baseURL = baseURL;
NSLog(@"URL Created");
RKObjectMapping *regionMapping = [RKObjectMapping mappingForClass:[Region class]];
[regionMapping mapKeyPathsToAttributes:@"regionHome", @"regionHome", @"regionID", @"regionID", @"regionName", @"regionName", @"parentCount", @"parentCount", @"parentID", @"parentID", @"childrenCount", @"childrenCount", @"parentName", @"parentName", nil];
[objectManager.mappingProvider setMapping:regionMapping forKeyPath:@""];