0

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

[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];

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

难道我做错了什么?

谢谢。

4

1 回答 1

2

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

[RKObjectManager setSharedManager:[RKObjectManager managerWithBaseURL:[[NSURL alloc] initWithString:@"http://localhost:8080"]]];
于 2012-07-07T12:31:27.177 回答