私のコードは以下の通りです:
NSString *urlString = [[NSString stringWithFormat:@"/players?skip=%ld",(long)skipSize] DVURL];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//[request set]
[request setValuesForKeysWithDictionary:[filter filteringDictionary]];
AFHTTPRequestOperation *operation =
[[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:
^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"responseObject %@", responseObject);
totalPages = ([[responseObject
objectForKey:@"count"] intValue] / 20);
NSLog(@"%@",[responseObject objectForKey:@"players"]);
for (NSDictionary *playerDict in [responseObject objectForKey:@"players"]) {
DVPlayer *player = [[DVPlayer alloc] initWithDictionary:playerDict];
if (![self.playerArray.players containsObject:player]) {
[self.playerArray.players addObject:player];
}
}
[playerCollectionView reloadData];
} failure:
^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", [error localizedDescription]);
[[[UIAlertView alloc]
initWithTitle:@"Error fetching players!"
message:@"Please try again later"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}];
[operation start];
を使うときはGETメソッドのパラメータとしてAFHTTPRequestOperationManager
使っていました。NSDictionary
だから対応すると思っ[request setValuesForKeysWithDictionary:[filter filteringDictionary]];
た。
しかし、エラーが発生しました:
setValue:forUndefinedKey:]: このクラスは、name(ex) のキー値コーディングに準拠していません
NSDictionary
便宜上、パラメータを設計しました...ではなくNSDictionary
を使用するときのようにパラメータを設定できませんか?AFHTTPRequestOperation
AFHTTPRequestOperationManager
お願い助けて