2016-06-21 19 views
0

Ich habe ein Array innerhalb eines Arrays holen als officeList in dem folgenden Format benannt: -Wie jeden Wert von Array von Strings innerhalb eines Array

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

Problem ist ich dieses Array bekam durch die JSON-Datei konvertieren in ein Array und als Ergebnis davon habe ich dieses Array von String innerhalb eines Arrays. Was ich will, ist jeder Wert eins nach dem anderen, wie zu holen: „Aussicht“, „vorschlagen“, usw.

ich folgenden Code verwende Daten zu holen:

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

Sie brauchen eine weitere Schleife, um jedes Element von '_officelist [i]' zu durchlaufen? – Paulw11

+0

Ihr Code mit Fehler, officelist und officeSize count möglicherweise Nebel übereinstimmen, so dass Sie nicht schreiben können val = [officeSize objectAtIndex: i]; direkt –

+0

Wenn ich nicht ID-Typ verwenden, um NSArray in CGFloat zu konvertieren, was dann zu verwenden? –

Antwort

1

Bewerben Code unten helfen,

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 Ihnen hilft.

+0

Danke dude .. es ist fertig .. –

+0

Gern geschehen, dude ..! –

2

Sie versuchen Lassen Sie sich diese

NSMutableArray *arr = [[NSMutableArray alloc] init]; 
for (NSArray *objArr in jsonArr) { 
    for (NSString *str in ObjArr) { 
     [arr addObject:str]; 
    } 
} 

Hier ist jsonArr das Array, das Sie von der Antwort bekommen. Verwenden Sie jetzt arr, um auf jedes gewünschte Objekt zuzugreifen.

Hope this Sie

Verwandte Themen