2017-05-09 54 views
0

我在iOS的新的和我面對關於連接兩個可變數組如何連接在目標C上兩個可變數組

在第一陣列我得到的值這樣

<__NSArrayI 0x7f9102d7a100>(
12/05/2017, 
17/05/2017, 
17/05/2017, 
17/05/2017, 
17/05/2017, 
22/05/2017, 
22/05/2017, 
22/05/2017, 
22/05/2017, 
22/05/2017, 
22/05/2017, 
22/05/2017, 
22/05/2017, 
22/05/2017, 
22/05/2017, 
22/05/2017, 
23/05/2017, 
23/05/2017 
) 

在第二個問題陣列

<__NSArrayI 0x7f9102d7a360>(
17:12, 
14:11, 
14:25, 
17:07, 
18:11, 
10:04, 
10:05, 
10:07, 
10:53, 
13:05, 
16:01, 
16:31, 
16:38, 
17:40, 
17:44, 
17:47, 
09:38, 
11:25 
) 

我需要顯示陣列這樣

12/05/2017 17:12 

我該怎麼做? 在此先感謝!

回答

2

簡單如下。

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

for (int i=0;i<firstArray.count;i++) { 
    [finalArray addObject:[NSString stringWithFormat:@"%@ %@", [firstArray objectAtIndex:i], [secondArray objectAtIndex:i]]]; 
} 
+0

@FahimParker完美的解決方案,易於use.Thank你。 – Muju

1

這種方式與計數檢查

NSArray *arr1 = @[@"12/05/2017", 
        @"17/05/2017"]; 
    NSArray *arr2 = @[@"17:12", 
         @"14:11"]; 
    NSMutableArray *result = [NSMutableArray new]; 

    NSAssert(arr1.count == arr2.count, @"arrays count not equal"); 

    for (int i = 0; i < arr1.count; i++) { 
     [result addObject:[NSString stringWithFormat:@"%@ %@", arr1[i], arr2[i]]]; 
    } 
0

你可以這樣做也

NSMutableArray *array1 = [@[@"111",@"222"] mutableCopy]; // sample array 
NSMutableArray *array2 = [@[@"333",@"444"] mutableCopy]; // sample array 
NSMutableArray *array3 = [NSMutableArray arrayWithArray:array1]; 
[array3 addObjectsFromArray:array2];