一个简单的数组合并问题

用的笨办法,写给自己看的


NSArray * array = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9", nil];

NSInteger logIndex = 0;

NSMutableArray * tesarray;

NSMutableArray * finalArray = [[NSMutableArray alloc] init];

for (int i = 0; i < array.count; i++)

{

logIndex = logIndex + 1;

if (logIndex == 1)

{

tesarray = [[NSMutableArray alloc] init];

}

NSString * model = [array objectAtIndex:i];

[tesarray addObject:model];

if (i == array.count - 1)

{

if ((i+1)%2 != 0)

{

[finalArray addObject:tesarray];

}

}else

{

if (logIndex == 2)

{

logIndex = 0;

[finalArray addObject:tesarray];

}

}

}

NSLog(@"++++%@",finalArray);

你可能感兴趣的:(一个简单的数组合并问题)