RKObjectManager没有活动:loadObjectsAtResourcePath:

时间:2012-05-16 20:51:00

标签: restkit

这是我用来从后端加载User对象的代码:

[RKObjectManager managerWithBaseURL:[[NSURL alloc] initWithString:@"http://localhost:8080"]];
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping mapKeyPath:@"id" toAttribute:@"id"];
[userMapping mapKeyPath:@"userName" toAttribute:@"userName"];
[userMapping mapKeyPath:@"firstName" toAttribute:@"firstName"];
[userMapping mapKeyPath:@"lastName" toAttribute:@"lastName"];
[userMapping mapKeyPath:@"email" toAttribute:@"email"];
[userMapping mapKeyPath:@"facebookId" toAttribute:@"facebookId"];
[userMapping mapKeyPath:@"twitterId" toAttribute:@"twitterId"];


[[RKObjectManager sharedManager].mappingProvider setObjectMapping:userMapping forResourcePathPattern:@"/users"];    
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/users" delegate:self];

此代码运行没有问题,但没有请求到达服务器,并且客户端没有调用委托方法。

我做错了吗?

感谢。

1 个答案:

答案 0 :(得分:2)

您的代码中未初始化共享管理器。 将您发布的代码中的第一行替换为:

[RKObjectManager setSharedManager:[RKObjectManager managerWithBaseURL:[[NSURL alloc] initWithString:@"http://localhost:8080"]]];