//Your original array
NSArray *homePlayersArray = [[NSArray alloc] initWithObjects:
[NSNumber numberWithInt:2],
[NSNumber numberWithInt:3],
[NSNumber numberWithInt:5],
[NSNumber numberWithInt:6],
[NSNumber numberWithInt:4],nil];
//For your 2D array
NSMutableArray *secondArray = [[NSMutableArray alloc] initWithCapacity:[homePlayersArray count]];
//populate as required
for(int i=0;i<[homePlayersArray count];i++){
NSArray *tempArray = [[NSArray alloc] initWithObjects:[homePlayersArray objectAtIndex:i],[NSNumber numberWithInt:0], nil];
[secondArray addObject:tempArray];
}
//print out some results to show it worked
NSLog(@"%@%@",@"secondArray first object value 0: ",[[secondArray objectAtIndex:0] objectAtIndex:0]);
NSLog(@"%@%@",@"secondArray first object value 1: ",[[secondArray objectAtIndex:0] objectAtIndex:1]);
NSLog(@"%@%@",@"secondArray second object value 0: ",[[secondArray objectAtIndex:1] objectAtIndex:0]);
NSLog(@"%@%@",@"secondArray second object value 1: ",[[secondArray objectAtIndex:1] objectAtIndex:1]);
爲什麼它使用方括號? – Ilario
那只是爲了顯示2維數組 – user3033493
爲什麼你不使用2個dim數組?創建2個暗淡的數組,不要打擾之間的轉換。在objective-c中不存在2個暗淡數組,您應該使用C像2個暗淡數組。如果您需要幫助,請參閱此鏈接(http://stackoverflow.com/questions/20498584/objective-c-2-dimentional-array?answertab=active#tab-top)。 – Greg