Значение в URL-адресе getPathIOS

Программируем под IOS
Ответить
Anonymous
 Значение в URL-адресе getPath

Сообщение Anonymous »

Я использую AFnetworking для загрузки местоположений в первом представлении моего приложения для iOS:
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);

}];

Ответ от API:
{
"created_at" = "2013-02-23T19:17:37Z";
id = 1;
lat = "51.463842";
long = "-0.6504559999999628";
name = Legoland;
"street_address" = "Winkfield Road, Windsor, United Kingdom";
"updated_at" = "2013-02-23T19:17:37Z";
},

Я показываю имя и street_address:
Изображение

Когда пользователь нажимает на местоположение, приложение iOS переходит к BeerTableViewController. Я хотел бы получить список пива в местах, по которым нажимали, используя что-то вроде этого запроса.
BeerTableViewController.m

NSString *path = [NSString stringWithFormat:@"locations/%@/beers.json",
[dictionary objectForKey:@"location_id"]];

[[LocationApiClient sharedInstance] getPath:path 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);

}];

Я не знаю, как передать значение location_id из ячейки LocationTableViewController, когда пользователь щелкает ее, чтобы оно заполнило URL-адрес getPath соответствующим значением. Нажатие на местоположение 1 приведет к установке URL-адреса getPath в BeerTableViewController на @"locations/1/beers.json
Ответ, который я получаю на этот запрос:{
"created_at" = "2013-02-23T19:27:10Z";
description = Awesome;
id = 2;
"location_id" = 1;
name = Pliny the Elder;
price = "3.50";
style = IPA;
"updated_at" = "2013-02-23T19:27:10Z";
}

Сейчас я получаю ошибки в моем запросе BeerTableViewController.m:

Неизвестный получатель «словарь» Нет известного класса метод для селектора objectForKey

NSString *path = [NSString stringWithFormat:@"locations/%@/beers.json",
[dictionary objectForKey:@"location_id"]];

Следует ли мне это настроить в:
LocationTableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath


Подробнее здесь: https://stackoverflow.com/questions/151 ... etpath-url
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»