我正在从我的API解析JSON工作正常,但每次我选择一行并进入详细视图时,他会告诉我产品应该链接到最底部显示的产品。我不明白为什么它没有解析特定行的产品ID,因为我已将其设置为解析indexPath.row
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *neuheitenCell = @"neuheitenCell";
CJHomeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:neuheitenCell];
wareID = [[arrayArtikelWareID objectAtIndex:indexPath.row] objectForKey:@"ware_id"];
NSLog(@"Waren ID: %@", wareID);
cell.artikelName.text = [[arrayArtikelName objectAtIndex:indexPath.row] objectForKey:@"name"];
cell.artikelHersteller.text = [[arrayArtikelHersteller objectAtIndex:indexPath.row] objectForKey:@"lieferant_name"];
return cell;
}
**编辑:
-(void) parseJSONWithURL: (NSURL *) jsonURL {
dispatch_async(mainThreadQueue, ^{
NSError *error = nil;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString *json =[NSString stringWithContentsOfURL:jsonURL encoding:NSUTF8StringEncoding error:&error];
if (error == nil) {
NSData *jsonData = [json dataUsingEncoding:NSUTF8StringEncoding];
dictionaryNewStuff = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
if (error == nil) {
dispatch_async(dispatch_get_main_queue(), ^{
arrayNeuheiten = [[dictionaryNewStuff valueForKey:@"newstuff"] valueForKey:@"Neuheiten"];
arrayArtikelBild = [[dictionaryNewStuff valueForKey:@"newstuff"] valueForKey:@"Neuheiten"];
[neuheitenTableView reloadData];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
});
}
}
});
}
可以在API查看JSON 有谁知道如何解决这个问题?
提前致谢!
答案 0 :(得分:0)
您可以尝试使用以下代码吗?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *neuheitenCell = @"neuheitenCell";
CJHomeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:neuheitenCell];
NSDictionary *object = [arrayNeuheiten objectAtIndex:indexPath.row];
NSString *wareID = [object objectForKey:@"ware_id"];
NSLog(@"Waren ID: %@", wareID);
cell.artikelName.text = [object objectForKey:@"name"];
cell.artikelHersteller.text = [object objectForKey:@"lieferant_name"];
return cell;
}
为什么需要两个数组来保存数据?我的意思是以下几行“arrayNeuheiten = [[dictionaryNewStuff valueForKey:@”newstuff“] valueForKey:@”Neuheiten“]; arrayArtikelBild = [[dictionaryNewStuff valueForKey:@”newstuff“] valueForKey:@”Neuheiten“];”
你在哪里为arrayArtikelWareID,arrayArtikelName,arrayArtikelHersteller
分配任何东西