0

我有三个array..say array1,array2,array3。所有这些数组都包含字典。现在,我想将这些数组的所有对象复制到一个数组中并显示在表格视图中。我的问题是我将如何将这三个数组复制到 1 中。说;

NSMutableArray *array1 = [NSMutableArray arrayWithObject:Dict1];
    NSMutableArray *array2 = [NSMutableArray arrayWithObject:Dict2];
    NSMutableArray *array3 = [NSMutableArray arrayWithObject:Dict3];   

现在,我想将array1、array2、array3 的包含复制到array4。我将如何执行此操作。

4

4 回答 4

2

用这个

NSMutableArray *array4 = [[NSMutableArray alloc] init];
[array4 addObjectsFromArray:array1];
[array4 addObjectsFromArray:array2];
[array4 addObjectsFromArray:array3];

//Do something on array4

[array4 release];
于 2012-06-06T20:09:54.643 回答
1
NSMutableArray *allObjs = [[NSMutableArray alloc] initWithArray: array1];
[allObjs addObjectsFromArray: array2];
[allObjs addObjectsFromArray: array3];
于 2012-06-06T20:06:36.530 回答
0
NSMutableArray *array4 = [[NSMutableArray alloc] init];

for (int i = 0; i < [array1 count]; i++)
{
    [array4 addObject:[array1 objectAtIndex:i]];
}
for (int i = 0; i < [array2 count]; i++)
{
    [array4 addObject:[array2 objectAtIndex:i]];
}
for (int i = 0; i < [array3 count]; i++)
{
    [array4 addObject:[array3 objectAtIndex:i]];
}

//use your array4

 [array4 release];
于 2012-06-06T20:04:17.717 回答
-1
NSMutableArray * array4 = [NSMutableArray arrayWithObjects:[array1 objectAtIndex:0], [array2 objectAtIndex:0], [array3 objectAtIndex:0]];
于 2012-06-06T20:03:27.773 回答