2017-07-07 41 views
-2

在我的ios應用程序中, 我在一個數組中有一些數據,現在我想用NSlog在viewdidload的幫助下打印該數據,但是我想顯示在一個for循環內的數據...所以我沒有得到什麼應該是我的循環。如何從循環中獲取數組中的值

我想從數組中獲取值的使用for ...循環......我該怎麼做?

storedDataArray = [[NSMutableArray alloc]init]; 

[storedDataArray addObject:@"Kaushal"]; 

[storedDataArray addObject:@"Bhaumik"]; 

[storedDataArray addObject:@"Arpit"]; 

[storedDataArray addObject:@"Swapnil"]; 

[storedDataArray addObject:@"Megha"]; 

[storedDataArray addObject:@"Ravi"]; 

for (int i=0; i<=6; i++) { 
    NSLog(@"hello %d",storedDataArray); 
} 
+0

使用'storedDataArray [I]'做與'storedDataArray.count'取代靜態6 –

回答

1

for (int i=0; i<=6; i++) { 
NSLog(@"hello %d",storedDataArray); 
} 

for (int i=0; i<storedDataArray.count; i++) { 
NSLog(@"hello %@",storedDataArray[i]); 
} 

快速enumration

for (NSString *name in storedDataArray) { 
NSLog(@"hello %@",name); 
} 
0

您必須添加索引i ñstoredDataArray

for (int i=0; i<storedDataArray.count; i++) { 
    NSLog(@"hello %@",storedDataArray[i]); 
} 

或者您可以不用指數

for (NSString *str in storedDataArray) { 
    NSLog(@"hello %@",str); 
}