[英]How to change a value in a two dimensions NSMutableArray?
I'm new to OC. 我是OC的新手。
In Swift, it's really easy to change a value in a two dimensions array. 在Swift中,更改二维数组中的值确实很容易。 Just like this a[0][0] = "1"
就像这样a[0][0] = "1"
But I'm really confused now about how to do it in OC. 但是我现在真的很困惑如何在OC中进行操作。
Thank you for any advice. 感谢您的任何建议。
self.infos =
[NSMutableArray arrayWithObjects: [NSMutableArray arrayWithObjects:@"11", @"22", @"33", @"44", @"55", @"66", nil],
[NSMutableArray arrayWithObjects:@"aa", nil], nil];
For example. 例如。 how to set aa
to bb
? 如何将aa
设置为bb
?
BTW, is it right way to declare infos
in @interface
? 顺便说一句,在@interface
声明infos
是正确的方法吗?
@property (strong, nonatomic) NSMutableArray* infos;
Try simple 简单尝试
self.infos[1][0] = @"newValue";
or Complex 或复杂
NSArray*fr = [self.infos objectAtIndex:1];
[fr replaceObjectAtIndex:0 withObject:@"newValue"];
顺便说一句,您实际上可以这样写:
infos[1][0] = @"bb";
Like this: 像这样:
NSMutableArray *infos = [NSMutableArray arrayWithObjects:
[NSMutableArray arrayWithObjects:@"11", @"22", @"33", @"44", @"55", @"66", nil],
[NSMutableArray arrayWithObjects:@"aa", nil],
nil];
[infos[0] setObject:@"1" atIndexedSubscript:0];
or 要么
infos[0][1] = @"2";
self.infos[1]
获取第二个数组,就像这样: self.infos[1]
self.infos[1][0]
获取第二个数组的“ aa”, self.infos[1][0]
self.infos[1][0] = @"bb";
将新的bb设置为aa self.infos[1][0] = @"bb";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.