简体   繁体   English

目标c中的2d和3d arrays ...帮助?

[英]2d and 3d arrays in objective-c…HELP?

Im new to objective-c programming and im currently working on an iPhone project and my task has to deal with 2d and 3d arrays, I have actually been trying for a while but im not sure if im on the right track.我是 objective-c 编程的新手,我目前正在做一个 iPhone 项目,我的任务必须处理 2d 和 3d arrays,我实际上一直在尝试正确的轨道,但我不确定。 Im trying to achieve the following:我试图实现以下目标:

1)Trip 1 must be in index 0 of array1 2)Trip 1 has departure time, arrival time and trip instructions 3)now im trying to have the departure in array2 index 0 that's being pointed to by trip1 in array1 in index zero, and arrival in array2 index 1 4)array2 will have array3 that has instructions for trip one 1)行程 1 必须在数组 1 的索引 0 中 2)行程 1 具有出发时间、到达时间和行程指令 3)现在我试图在数组 2 索引 0 中的出发点由数组 1 中的行程 1 在索引 0 中指向,并且到达 array2 索引 1 4)array2 将有 array3 具有行程一的指令

I have for loops and everything is working perfectly i just need to know how to do the above, in other words how to save these information in the manner i have described in the above steps?我有 for 循环,一切正常我只需要知道如何执行上述操作,换句话说,如何以我在上述步骤中描述的方式保存这些信息?

i have done this but not sure if im right or wrong: Array1 = [[NSmutableArray] init];我已经这样做了,但不确定我是对还是错:Array1 = [[NSmutableArray] init]; Array2 = [[NSmutableArray] inti]; Array2 = [[NSmutableArray] inti]; [Array1 insertObject:Array2 atIndex:0]; [Array1 insertObject:Array2 atIndex:0];

[Array1 addObject:ObjectToAdd, i] [Array2 addObject:ObjectToAdd, i] [Array1 addObject:ObjectToAdd, i] [Array2 addObject:ObjectToAdd, i]

Note: "i" starts from zero注意:“i”从零开始

Thank you,谢谢,

You can use a NSMutableArray and insert different objects into it.您可以使用 NSMutableArray 并将不同的对象插入其中。 For example you have 3 classes say A, B, C例如,您有 3 个类,例如 A、B、C

NSMutableArray mainArray = [NSMutable array];
A array1 = [A new];
B array2 = [B new];
C array3 = [C new];

[mainArray addObject:array1];
[mainArray addObject:array2];
[mainArray addObject:array3];

Now you can access these objects via your mainArray .现在您可以通过mainArray访问这些对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM