Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two dimensional array in ios

I want to use two dimensional array in ios, for example I want to prepare an array for tableview datasource,

UITableViewCell array[sections][rows];

Something like this, and here I cant predeclare the size also.

Thanks

like image 732
sachin Avatar asked May 28 '12 12:05

sachin


2 Answers

NSMutableArray *dataArray = [[NSMutableArray alloc] initWithCapacity: 3];

[dataArray insertObject:[NSMutableArray arrayWithObjects:@"0",@"0",@"0",nil] atIndex:0];
[dataArray insertObject:[NSMutableArray arrayWithObjects:@"0",@"0",@"0",nil] atIndex:1];
[dataArray insertObject:[NSMutableArray arrayWithObjects:@"0",@"0",@"0",nil] atIndex:2];

And this is how you select your value from array

NSMutableArray *subArray = [dataArray objectAtIndex:2];
NSLog(@"data : %@",[subArray objectAtIndex:0]);
like image 187
Saad Avatar answered Nov 02 '22 23:11

Saad


set up an NSDictionary and use an NSIndexPath as the key for each cell

like image 27
wattson12 Avatar answered Nov 02 '22 23:11

wattson12