// ds.data = [NSArray arrayWithObjects:
// [NSArray arrayWithObjects:@"黑", @"0", @"0", @"0", @"0",@"0", @"0",@"0",nil],
// [NSArray arrayWithObjects:@"深蓝", @"0", @"0", @"0", @"0", @"0", @"0",@"0",nil],
// [NSArray arrayWithObjects:@"杏", @"0", @"0", @"0", @"0", @"0", @"0",@"0",nil],
// [NSArray arrayWithObjects:@"白", @"0", @"0", @"0", @"0", @"0", @"0",@"0",nil],
// [NSArray arrayWithObjects:@"红", @"0", @"0", @"0", @"0", @"0", @"0",@"0",nil],
// [NSArray arrayWithObjects:@"降红", @"0", @"0", @"0", @"0", @"0", @"0",@"0",nil],
// [NSArray arrayWithObjects:@"合计", @"0", @"0", @"0", @"0", @"0", @"0",@"0",nil],
// nil];
怎么生成这样的二维数组,行与列都是可变的。二维数组
NSArray换成NSMutableArray试下。
NSMutableArray *dataMArray=[[NSMutableArray alloc] init];
//NSMutableArray *dataMArray=[NSMutableArray arrayWithCapacity:[colourArray count]+1];
for (int r=0; r<[sizeArray count]+2; r++)
{
[dataMArray addObject:[[NSMutableArray alloc] init]];
}
NSMutableArray *colourRowMArray=[[NSMutableArray alloc] init];
for (int p=0; p<[colourArray count]+1; p++)
{
if (p==[colourArray count])
{
for (int q=0; q<[sizeArray count]+2; q++)
{
if (q==0)
{
[colourRowMArray addObject:@"合计"];
}
else
{
[colourRowMArray addObject:@"0"];
}
}
}
else
{
for (int q=0; q<[sizeArray count]+2; q++)
{
if (q==0)
{
[colourRowMArray addObject:[colourArray objectAtIndex:p]];
}
else
{
[colourRowMArray addObject:@"0"];
}
NSLog(@"colourRowMArray:%@",colourRowMArray);
}
}
NSLog(@"p%d,%@",p,colourRowMArray);
[[dataMArray objectAtIndex:p] addObject:colourRowMArray];//向动态数组NSMutableArray中添加动态数组NSMutableArray的方法
NSLog(@"dataMArray:%@",dataMArray);
}