Это запрос AFNetworking, который я использую для получения данных о местоположении:
LocationTableViewController.m
Код: Выделить всё
[[LocationApiClient sharedInstance] getPath:@"locations.json" parameters:nil
success:^(AFHTTPRequestOperation *operation, id response) {
NSLog(@"Response: %@", response);
NSMutableArray *results = [NSMutableArray array];
for (id locationDictionary in response) {
Location *location = [[Location alloc] initWithDictionary:locationDictionary];
[results addObject:location];
}
self.results = results;
[self.tableView reloadData];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error fetching locations!");
NSLog(@"%@", error);
}];
Код: Выделить всё
{
"created_at" = "2013-02-23T19:25:26Z";
id = 2;
lat = "48.870175";
long = "2.779899999999998";
name = "Disneyland Hotel";
"places_id" = fd90769e2cf40d6cb6cb1a3d0bfd0ce5d37ed331;
"street_address" = "Rue de la Marni\U00e8re, Chessy, France";
"updated_at" = "2013-02-23T19:25:26Z";
},
[img]https://i.sstatic. net/d7IM3.png[/img]
Когда пользователь нажимает на ячейку местоположения, я хотел бы отобразить табличное представление списка пива в этом месте. Маршрут Rails APPI (для location_id => 1) — http://localhost:3000/locations/1/beers.json и выводит следующий JSON для пива, которое принадлежит location_id:1:
Код: Выделить всё
{
"created_at":"2013-02-23T19:25:53Z",
"description":"fkjgvjkg",
"id":1,"location_id":1,
"name":"nhoihioh",
"price":"2.5","style":"ipa",
"updated_at":"2013-02-23T19:25:53Z"
}
Как вставить location_id в следующий запрос AFNetworking, который возникает в следующем представлении таблицы, когда пользователь нажимает на местоположение ячейка?
BeerTableViewController.m
Код: Выделить всё
[[LocationApiClient sharedInstance] getPath:@"locations/**(location_id from location table cell inserted here)**/beers.json" parameters:nil
success:^(AFHTTPRequestOperation *operation, id response) {
NSLog(@"Response: %@", response);
NSMutableArray *results = [NSMutableArray array];
for (id beerDictionary in response) {
Beer *beer = [[Beer alloc] initWithDictionary:beerDictionary];
[results addObject:beer];
}
self.results = results;
[self.tableView reloadData];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error fetching beers!");
NSLog(@"%@", error);
}];
Подробнее здесь: https://stackoverflow.com/questions/151 ... am-request