6

我有三个NSArray对象。我需要将此数组的所有对象添加到NSArray称为allMyObjects的对象中。

NSArray标准的解决方案,例如通过初始化方法,还是我需要自定义方法来从其他数组中检索所有对象并将所有检索到的对象放入我的allMyObjects数组?

4

4 回答 4

26

不知道这是否算作您的问题的一个足够简单的解决方案,但这是直接的方法(正如其他回答者所暗示的那样):

NSMutableArray *allMyObjects = [NSMutableArray arrayWithArray: array1]; 
[allMyObjects addObjectsFromArray: array2]; 
[allMyObjects addObjectsFromArray: array3]; 
于 2013-03-29T13:58:01.743 回答
6

一旦看到这个,

NSArray *newArray=[[NSArray alloc]initWithObjects:@"hi",@"how",@"are",@"you",nil];
    NSArray *newArray1=[[NSArray alloc]initWithObjects:@"hello",nil];
    NSArray *newArray2=[[NSArray alloc]initWithObjects:newArray,newArray1,nil];
    NSString *str=[newArray2 componentsJoinedByString:@","];
    NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"()\n "];
    str = [[str componentsSeparatedByCharactersInSet:doNotWant] componentsJoinedByString: @""];
     NSArray *resultArray=[str componentsSeparatedByString:@","];
    NSLog(@"%@",resultArray);

运单:-

(
    hi,
    how,
    are,
    you,
    hello
)
于 2013-03-29T14:14:41.287 回答
4

您可以在数组上调用addObjectsFromArray:方法。allMyObjects

于 2013-03-29T13:43:37.147 回答
0

这是添加代码以存储和从数组到数组中获取数据。

将数组存储到数组

NSMutableArray rowOneRoundData = [NSMutableArray arrayWithObjects: @"45",@"29",@"12",nil];
 NSMutableArray   rowTwoRoundData = [NSMutableArray arrayWithObjects: @"41",@"45",@"45",nil];
   NSMutableArray rowThreeRoundData = [NSMutableArray arrayWithObjects: @"12",@"45",@"22",nil];
   NSMutableArray rowFourRoundData = [NSMutableArray arrayWithObjects: @"45",@"12",@"61",nil];
   NSMutableArray rowFiveRoundData = [NSMutableArray arrayWithObjects: @"12",@"14",@"14",nil];
   NSMutableArray rowSixRoundData = [NSMutableArray arrayWithObjects: @"12",@"12",@"12",nil];
   NSMutableArray rowSevenRoundData = [NSMutableArray arrayWithObjects: @"12",@"36",@"83",nil];
   NSMutableArray rowEightRoundData = [NSMutableArray arrayWithObjects: @"37",@"57",@"45",nil];
   NSMutableArray rowNineRoundData = [NSMutableArray arrayWithObjects: @"12",@"93",@"83",nil];
   NSMutableArray rowTenRoundData = [NSMutableArray arrayWithObjects: @"16",@"16",@"16",nil];
   NSArray circleArray = [[NSArray alloc]initWithObjects:rowOneRoundData,rowTwoRoundData,rowThreeRoundData,rowFourRoundData,rowFiveRoundData,rowSixRoundData,rowSevenRoundData,rowEightRoundData,rowNineRoundData,rowTenRoundData, nil];

从圆形数组中获取数据

for (int i= 0; i<10;i++)
{
NSArray *retriveArrar = [[circleArray objectAtIndex:i] mutableCopy];
}
于 2015-12-10T12:05:25.910 回答