Objective c RestKit在映射时混淆了类

Objective c RestKit在映射时混淆了类,objective-c,ios,xcode,xcode4,restkit,Objective C,Ios,Xcode,Xcode4,Restkit,我正在开发一个应用程序,它根据web服务提供的信息创建表视图。我目前有两个表视图,一个用于“区域”,另一个用于“类别”,并且正在使用RestKit将JSON信息映射到适当的类。我有“Region”和“Category”类来保存每个项目的数据。如果每个表都是第一个要查看的表,那么它似乎可以正常工作。但是,如果我查看一个表,然后切换到另一个表,则程序会遇到异常。如果我先查看一个表,然后再查看另一个表,似乎会将我的类别和区域类弄混 当我首先进入类别视图,然后进入区域视图时,我会出现以下异常: “由于未

我正在开发一个应用程序,它根据web服务提供的信息创建表视图。我目前有两个表视图,一个用于“区域”,另一个用于“类别”,并且正在使用RestKit将JSON信息映射到适当的类。我有“Region”和“Category”类来保存每个项目的数据。如果每个表都是第一个要查看的表,那么它似乎可以正常工作。但是,如果我查看一个表,然后切换到另一个表,则程序会遇到异常。如果我先查看一个表,然后再查看另一个表,似乎会将我的类别和区域类弄混

当我首先进入类别视图,然后进入区域视图时,我会出现以下异常: “由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[Category regionName]:未识别的选择器已发送到实例0x938f1a0'”

当我转到“区域”视图,然后是“类别”视图时,我会看到以下内容: “由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[Region categoryName]:无法识别的选择器已发送到实例0xce87240'”

这是相关代码。我意识到这是很多代码,但我不知道我的问题在哪里:

如果有人知道怎么回事,我会感谢你的帮助。谢谢大家!

类别视图:

- (void)viewDidLoad
{
    [super viewDidLoad];

    mCategoryId = [NSNumber numberWithInt:0];
    NSLog(@"Categories");

    RKURL *baseURL = [RKURL URLWithBaseURLString:@"My URL"];
    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:@""];

    [self sendRequest];

}


- (void) sendRequest {
    RKObjectManager *objectManager = [RKObjectManager sharedManager];
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[NSDictionary dictionaryWithObject:mCategoryId forKey:@"CategoryId"] options:0 error:&error];


    [objectManager loadObjectsAtResourcePath:@"/api/Main/Process" usingBlock:^(RKObjectLoader *loader) {
        loader.params = [RKRequestSerialization serializationWithData:jsonData MIMEType:RKMIMETypeJSON];
        loader.method = RKRequestMethodPOST;
        loader.serializationMIMEType = RKMIMETypeJSON;

        NSDictionary *headers = [NSDictionary dictionaryWithObjectsAndKeys:@"application/json", @"Content-Type", @"Basic ClientIdentifier%3Afc_ios_client%2CEndpoint%3A%2FCategories%2FGetChildCategoriesById", @"Authorization", nil];
        loader.additionalHTTPHeaders = headers;
        loader.onDidLoadObjects = ^(NSArray *objects) {
            NSLog(@"Objects Loaded");
            categories = objects;
            [self.tableView reloadData];
        };
    loader.onDidFailWithError = ^(NSError *error) {
            NSLog(@"Error %@", [error localizedDescription]);  
        };
        NSLog(@"%@",[NSString stringWithFormat:@"%@%@", loader.URL.baseURL, loader.URL.relativePath]);
        loader = nil;
    }];
    objectManager = nil;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    Category *category = [[Category alloc] init];
    category = nil;
    category = [categories objectAtIndex:indexPath.row];
    NSLog(@"Category Cell");
    cell.textLabel.text = category.categoryName;
    NSLog(@"Cell returned");

    return cell;
}
区域视图:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"Region Listings Loading");

    mRegionId = [NSNumber numberWithInt:1];

    RKURL *baseURL = [RKURL URLWithBaseURLString:@"My URL"];
    RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
    objectManager.client.baseURL = baseURL;

    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:@""];

    NSLog(@"Mapping done");

    [self sendRequest];

}
- (void) sendRequest {

    RKObjectManager *objectManager = [RKObjectManager sharedManager];
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[NSDictionary dictionaryWithObject:mRegionId forKey:@"RegionId"] options:0 error:&error];

    NSLog(@"JSON Data");


    [objectManager loadObjectsAtResourcePath:@"/api/Main/Process" usingBlock:^(RKObjectLoader *loader) {
        loader.params = [RKRequestSerialization serializationWithData:jsonData MIMEType:RKMIMETypeJSON];
        loader.method = RKRequestMethodPOST;
        loader.serializationMIMEType = RKMIMETypeJSON;

        NSDictionary *headers = [NSDictionary dictionaryWithObjectsAndKeys:@"application/json", @"Content-Type", @"Basic ClientIdentifier%3Afc_ios_client%2CEndpoint%3A%2FRegions%2FGetChildRegionsByIdWithBaseRegion", @"Authorization", nil];
        loader.additionalHTTPHeaders = headers;

        NSLog(@"Headers");

        loader.onDidLoadObjects = ^(NSArray *objects) {
            NSLog(@"Objects Loaded");
            regions = nil;
            regions = objects;
            [self.tableView reloadData];
        };
        loader.onDidFailWithError = ^(NSError *error) {
            NSLog(@"Error %@", [error localizedDescription]);  
        };
        NSLog(@"%@",[NSString stringWithFormat:@"%@%@", loader.URL.baseURL, loader.URL.relativePath]);
    }];

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    Region *region = [[Region alloc] init];
    region = nil;
    region = [regions objectAtIndex:indexPath.row];
    NSLog(@"region");
    cell.textLabel.text = region.regionName;

    return cell;
}

第二个视图控制器中的objectManager来自哪里?第二个视图控制器使用的代码与创建objectManager的代码基本相同。我将其添加到区域部分以澄清这一点。第二个视图控制器中的objectManager来自何处?第二个视图控制器使用的代码与创建objectManager的代码基本相同。我将其添加到区域部分以澄清这一点。