我有如下的示例json数据,我想在我的单元格列表中分配这些数据。目前,我的结果将在属性名称中显示错误。: -
{
"attribute_group_name" = Color;
"attribute_name" = (
Black,
White,
Gold,
Red
);
},
{
"attribute_group_name" = Service;
"attribute_name" = (
"Free Shipping",
Insurance
);
},
{
"attribute_group_name" = Telco;
"attribute_name" = (
Digi,
Maxis,
Celcom
);
},
{
"attribute_group_name" = Material;
"attribute_name" = (
Wood
);
},
{
"attribute_group_name" = Brand;
"attribute_name" = (
Apple,
Mi,
Gome,
HuaWei
);
},
这是我目前的输出。我的列表中有错误的属性名称(重复数据),但标题是正确的。
这是我在cellForItemAtIndexPath和numberOfItemsInSection中的代码。感谢您的帮助: -
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
FilterItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:FilterItemCellID forIndexPath:indexPath];
//HOW to set cell.attribute_name here?
NSLog(@"1 - %@",(NSArray *)[self.filterItem[indexPath.section] valueForKey:@"attribute_name"]);
// Result in 1 - (
// Black,
// White,
// Gold,
// Red
// )
// How can I set it accordingly in cell?
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return ((NSArray *)[self.filterItem[section] valueForKey:@"attribute_name"]).count;
}
答案 0 :(得分:1)
cell.attribute_name=[[self.filterItem[section] valueForKey:@"attribute_name"]objectAtIndex:indexPath.row];