我只有几个NSMutableArrays,例如arr1,arr2,arr3,arr4。如何将所有NSMutableArrays合并在一起?还是有任何方法可以多次追加到一个数组中?

例:

arr = [[NSMutableArray alloc] init];
//first loop
for(condition){
    [arr addObject:firstLoopValue];
}
//second loop
for(condition){
    [arr addObject:secondLoopValue];
}
//third loop
for(condition){
    [arr addObject:thirdLoopValue];
}


最后是最终结果{firstLoopValue...secondLoopValue...thirdLoopValue}

我是iOS新手,所以不知道是否有可能。提前致谢

编辑
我已经尝试过以下两种方式:

rCodeArr = [[NSMutableArray alloc] init];
rDateArr = [[NSMutableArray alloc] init];
rAmountArr = [[NSMutableArray alloc] init];

jCodeArr = [[NSMutableArray alloc] init];
jDateArr = [[NSMutableArray alloc] init];
jAmountArr = [[NSMutableArray alloc] init];
jBalanceArr = [[NSMutableArray alloc] init];

NSArray *component = [journal getComponents:custCode];
for(int i = 0; i < [component count]; i++){

    list = [component objectAtIndex:i];

    NSArray *timestamp = [list.jDate componentsSeparatedByString:@" "];
    NSString *splitdate = timestamp[0];

    [jCodeArr addObject:list.jCode];
    [jDateArr addObject:splitdate];
    [jAmountArr addObject:list.jAmount];
    [jBalanceArr addObject:list.jOutstanding];
}
NSArray *rcom = [receipt getComponents:custCode];
for(int j = 0; j < [rcom count]; j++){

    rList = [rcom objectAtIndex:j];

    NSArray *rtime = [rList.rDate componentsSeparatedByString:@" "];
    NSString *rsplit = rtime[0];

    [rCodeArr addObject:rList.rCode];
    [rDateArr addObject:rsplit];
    [rAmountArr addObject:rList.rAmount];
    [rBalanceArr addObject:@"N/A"];
}

lblOneArray = [NSMutableArray arrayWithArray:rCodeArr];

    [lblOneArray addObjectsFromArray:jCodeArr];
    lblTwoArray = [NSMutableArray arrayWithArray:rDateArr];

    [lblTwoArray addObjectsFromArray:jDateArr];
    lblThreeArray = [NSMutableArray arrayWithArray:rAmountArr];

    [lblThreeArray addObjectsFromArray:jAmountArr];
    lblFourArray = [NSMutableArray arrayWithArray:jBalanceArr];
    [lblFourArray addObjectsFromArray:rBalanceArr];




lblOneArray = [[NSMutableArray alloc] init];
lblTwoArray = [[NSMutableArray alloc] init];
lblThreeArray = [[NSMutableArray alloc] init];
lblFourArray = [[NSMutableArray alloc] init];
[lblOneArray addObjectsFromArray:rCodeArr];
[lblOneArray addObjectsFromArray:jCodeArr];

[lblTwoArray addObjectsFromArray:rDateArr];
[lblTwoArray addObjectsFromArray:jDateArr];

[lblThreeArray addObjectsFromArray:jAmountArr];
[lblThreeArray addObjectsFromArray:jAmountArr];

[lblFourArray addObjectsFromArray:rBalanceArr];
[lblFourArray addObjectsFromArray:jBalanceArr];


但是由于未捕获的异常“ NSRangeException”,消息仍会崩溃*****终止应用程序,原因:“ *-[__ NSArrayM objectAtIndex:]:索引5超出范围[0 .. 4]”

注意所有这些都是NSMutableArray

最佳答案

做就是了

arr = [[NSMutableArray alloc] init];
[arr addObjectsFromArray:anArray1];
[arr addObjectsFromArray:anArray2];
[arr addObjectsFromArray:anArray3];

09-26 19:22