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
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
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]);
set up an NSDictionary
and use an NSIndexPath
as the key for each cell
Syntactic sugar approach. Note that this approach will not automatically create a NSMutableArray
of a given size. The initial array size will be 0, 0.
NSMutableArray *yourArray = [@[ [@[] mutableCopy]] mutableCopy];
// add an object to the end of your array
[yourArray[section][row] addObject:@(22)];
// set/change an NSNumber object at a particular location in the 2D array.
yourArray[section][row] = @(22);
// Retrieve a value, converting the NSNumber back to a NSInteger
NSInteger result = [yourArray[section][row] integerValue];