Reputation: 111
I have sample json data as below and I would like to assign these data in my cell list. Currently my result will show wrongly in attribute name.:-
{
"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
);
},
And here is my current output. I have wrong attribute name in my list (duplicate data) but the header is correct.
Here is my code in cellForItemAtIndexPath and numberOfItemsInSection. Appreciated your help:-
- (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;
}
Upvotes: 0
Views: 38
Reputation:
cell.attribute_name=[[self.filterItem[section] valueForKey:@"attribute_name"]objectAtIndex:indexPath.row];
Upvotes: 1