0

在IOS中,我有这个数组:

multiDimensionArray = [NSMutableArray arrayWithObjects:[NSMutableArray arrayWithObjects:@"one",@"two", nil],[NSMutableArray arrayWithObjects:@"three", nil],[NSMutableArray arrayWithObjects:@"four", nil],nil];

然后我需要将其转换为:

singleDimensionArray = [NSMutableArray arrayWithObjects:[multiDimensionArray objectAtIndex:0], nil];

我没有得到 2 个对象(@"one" 和 @"two"),而是得到 1 个对象(@"one, two")。我怎样才能把它变成2个对象?谢谢!

4

2 回答 2

0

您的新数组只包含一个带有 2 个额外对象的数组。所以现在做同样的事情来创建包含 2 个对象的新数组。

twoObjectsArray = [singleDimensionArray objectAtIndex:0];

for (NSString *string in twoObjectsArray) {
    NSLog(@"%@,string);
}
于 2013-05-03T14:20:18.290 回答
0
NSMutableArray *array1=[[NSMutableArray alloc] initWithObjects:@"One",@"Two", nil];

NSMutableArray *array2 = [[NSMutableArray alloc] initWithObjects:@"Three",@"Four" ,nil];

NSMutableArray *array3 =[[NSMutableArray alloc] initWithObjects:array1,array2, nil];

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

for (NSMutableArray *array in array3)
{
    for (int i=0; i<[array count]; i++)
    {
        [array4 addObject:[array objectAtIndex:i]];
    }
}

NSLog(@"Final Array = %@",array4);

array3=nil;
array2=nil;
array1=nil;
于 2013-05-03T14:26:39.170 回答