Home  >  Q&A  >  body text

objective-c - OC中动态创建可变数组的问题

现有一数组,内有10个元素,已按元素的某一属性排序(比如时间字符串)。现在需要将数组中时间相同的元素取出,放入一个小数组中,再将这些小数组放入一个大数组中,请问该如何操作?最好有代码。此前都因为指针和变量作用域的问题而无法解决。

天蓬老师天蓬老师2757 days ago491

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-26 09:03:49

    Use NSMutableArray
    NSMutableArray * arr2=[NSMutableArray array];//The first step: define an empty variable array

    arr2=[NSMutableArray addObject:obj];//The second step is to put the elements you need inside. Your search method is not clearly written, so I only give you a rough idea here

    NSMutableArray *arrF=[NSMutableArray addObject:arr2];//Construct a two-dimensional variable array

    NSString * str = [[arrF ObjectAtIndex: (large array subscript)] ObjectAtIndex: (small array subscript)]; // Access elements in the array

    reply
    0
  • Cancelreply