我有一个数组,里面有一个名为officeList的数组,格式如下:
(
(
Prospect,
Propose
),
(
Open,
Fund,
Propose
),
(
Settle,
Review
)
)
问题是我通过将JSON文件转换为数组来获得此数组,结果,我在数组中获得了此字符串数组。我想要的是一个一个地获取每个值,例如:“前景”,“提议”等。
我正在使用以下代码来获取数据:
for (int i = 0;i<[_officelist count];i++)
{
id val=[officeSize objectAtIndex:i];
CGFloat val1=[val floatValue];
UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 20,val1,15)];
newLabel.text=[NSString stringWithFormat:@"%@",_officelist[i]];
newLabel.textAlignment = NSTextAlignmentCenter;
[self.roadmapCollectionView addSubview:newLabel];
x=x+val1;
}
最佳答案
应用下面的代码,
for (int i = 0; i < [_officelist count]; i++)
{
NSArray *valList=[_officelist objectAtIndex:i];
CGFloat val1 = [valList floatValue]; // Your Float val
for (int j = 0; j < [valList count]; j++)
{
UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 20,val1,15)];
newLabel.text = [NSString stringWithFormat:@"%@",valList[j]];
newLabel.textAlignment = NSTextAlignmentCenter;
[self.roadmapCollectionView addSubview:newLabel];
}
x=x+val1;
}
希望这对您有帮助。