shubham mishra shubham mishra - 5 months ago 10
Objective-C Question

How to fetch each value from Array of strings inside an Array

I have an array inside an array named as officeList in the following format :-

(
(
Prospect,
Propose
),
(
Open,
Fund,
Propose
),
(
Settle,
Review
)
)


Problem is i got this array by converting the json file into an array and as a result of that i got this array of string inside an array. What i want is to fetch each value one by one like : "prospect", "propose", etc.

I am using following code to fetch data :

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;
}

Answer

Apply below code,

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;
}

Hope this helps you.