初始化 2 个暗淡数组 NSMutableArray
对于 CI 来说,会初始化一个这样的数组:
NSInteger x[3][10];那行得通。
下面我有一个可以工作的暗淡数组。想要将所有这些移动到 2 维数组中,如何初始化它?换句话说,采用下面的代码并使其适用于二维。
NSMutableArray *SRData;
SRData = [[NSMutableArray alloc] init];
NSMutableDictionary *SRRow;
SRRow = [[NSMutableDictionary alloc] init];
[SRRow setObject:@"Read" forKey:@"Descr"];
[SRRow setObject:@"Read2.png" forKey:@"Img"];
[SRRow setObject:@"Read the codes" forKey:@"Det"];
[SRData addObject:SRRow] ;
[SRRow release];
For C I would init an array like this:
NSInteger x[3][10]; That works.
Below I have a one dim array that works. Would like to move all of this to a 2 dim array, How do I init it? So in other words take the code below and make it work with 2 dimensions.
NSMutableArray *SRData;
SRData = [[NSMutableArray alloc] init];
NSMutableDictionary *SRRow;
SRRow = [[NSMutableDictionary alloc] init];
[SRRow setObject:@"Read" forKey:@"Descr"];
[SRRow setObject:@"Read2.png" forKey:@"Img"];
[SRRow setObject:@"Read the codes" forKey:@"Det"];
[SRData addObject:SRRow] ;
[SRRow release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Objective-C 中,您只需拥有一个数组数组即可获取第二维。据我所知,没有速记,因此您只能执行以下操作:
因此您要做的就是将其他对象(在您的情况下为
NSMutableDictionary
s)添加到secondDimension
数组。用法如下:编辑
完整代码示例:
现在,要获取该“字段”,您将使用如下代码:
In Objective-C, you just have to have an array of arrays to get the second dimension. To my knowledge, there is no shorthand, so you're stuck doing something like the following:
So all you would do is add your other objects (in your case, the
NSMutableDictionary
s) to thesecondDimension
array. Usage would be like:Edit
Full code example:
Now, to get at that "field" you would use code such as the following: