Новинка для iOS. Я загружаю данные JSON с помощью AFNetworking и помещаю данные в объект Dictionary. Это делается в следующем коде:
-(void)locationRequest
{
NSURL *url = [NSURL URLWithString:@"http://sitespec/php/getlocations.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//AFNetworking asynchronous url request
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id responseObject)
{
self.locationsFromJSON = (NSDictionary *)responseObject;
NSLog(@"JSON RESULT %@", responseObject);
NSLog(@"JSON DICTIONARY %@", _locationsFromJSON);
[self.tableView reloadData];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id responseObject)
{
NSLog(@"Request Failed: %@, %@", error, error.userInfo);
}];
[operation start];
}
Я получаю данные и заполняю массив Dictionary, как видно из результатов вызовов NSLOG ниже:
2013-05-12 12:44:08.851 sitespec[2024:c07] JSON RESULT (
{
city = "Rocky Mount";
id = 1;
name = "Rocky Mount";
phone = "(252) 451-1811";
state = NC;
"street_address" = "620 Health Drive";
zip = 27804;
},
{
city = "Elizabeth City";
id = 2;
name = "Elizabeth City";
phone = "(252) 335-4355";
state = NC;
"street_address" = "109 Corporate Drive";
zip = 27906;
}
)
2013-05-12 12:44:08.852 sitespec[2024:c07] JSON DICTIONARY (
{
city = "Rocky Mount";
id = 1;
name = "Rocky Mount";
phone = "(252) 451-1811";
state = NC;
"street_address" = "620 Health Drive";
zip = 27804;
},
{
city = "Elizabeth City";
id = 2;
name = "Elizabeth City";
phone = "(252) 335-4355";
state = NC;
"street_address" = "109 Corporate Drive";
zip = 27906;
}
)
НО, вот где я потерял.....
Как мне получить доступ к этим данным в объекте Dictionary в моем
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
метод?
Что-то типа:
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [self.locationsFromJSON objectForKey:@"name"];
???
Это не работает, и я получаю ошибку SIGBART. Я просто не могу понять, как считывать данные и заполнять табличное представление?
Как мне это сделать? ЛЮБАЯ помощь ОЧЕНЬ приветствуется.....