目前我正在使用一个使用 RestKit 进行通信的 iOS 应用程序。我成功检索并添加了数据。但是从数据库中更新和删除数据不起作用。
我正在使用以下代码向数据库添加新条目:
[[RKClient sharedClient] get:@"/tblTests" delegate:self];
RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[Venue class]];
RKURL *baseURL = [RKURL URLWithBaseURLString:@"http://10.10.3.101/WcfService1/WcfDataService1.svc/"];
RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
objectManager.client.baseURL = baseURL;
[venueMapping mapKeyPathsToAttributes:@"Name",@"name", nil];
[objectManager.mappingProvider setMapping:venueMapping forKeyPath:@"value"];
[objectManager loadObjectsAtResourcePath:@"/tblTests/" delegate:self];
RKObjectMapping* venueMappingS = [RKObjectMapping mappingForClass:[Venue class]];
venueMappingS.setDefaultValueForMissingAttributes = YES;
[venueMappingS mapKeyPath:@"Name" toAttribute:@"name"];
RKObjectRouter *router = [[RKObjectRouter alloc] init];
[router routeClass:[Venue class] toResourcePath:@"/tblTests/"];
[router routeClass:[Venue class] toResourcePath:@"/tblTests/" forMethod:RKRequestMethodPOST];
[[[RKObjectManager sharedManager] mappingProvider] setMapping:venueMappingS forKeyPath:@"value"];
[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:[venueMappingS inverseMapping] forClass:[Venue class]];
[RKObjectManager sharedManager].router = router;
[RKObjectManager sharedManager].serializationMIMEType = RKMIMETypeJSON;
[RKObjectManager sharedManager].acceptMIMEType = RKMIMETypeJSON;
Venue *venueName = [[Venue alloc] init];
venueName.name = @"Midhun MP";
venueName.Id = 12;
[[RKObjectManager sharedManager] postObject:venueName delegate:self];
它工作得很好,然后我使用了相同的代码,只更改了这两行:
[router routeClass:[Venue class] toResourcePath:@"/tblTests/" forMethod:RKRequestMethodPOST];
[[RKObjectManager sharedManager] postObject:venueName delegate:self];
到
[router routeClass:[Venue class] toResourcePath:@"/tblTests/" forMethod:RKRequestMethodDELETE];
[[RKObjectManager sharedManager] deleteObject:venueName delegate:self];
这不工作!
我的场地课程:
@interface Venue : NSObject
@property (strong, nonatomic) NSString *name;
@property (nonatomic) int Id;
@end
我的 JSON 看起来像:
{"value":[{"Id":1,"Name":"Midhun"},{"Id":12,"Name":"Midhun MP"}]}
我找不到任何问题,请帮助我。