替换二维嵌套 NSMutableArray 内的对象
我在替换 NSMutableArray 中的对象时遇到问题,该对象是另一个 NSMutableArray 中的对象。
接口中:
NSMutableArray *tiles;
在实现中:
tiles = [[NSMutableArray alloc] initWithObjects: [NSMutableArray arrayWithObjects: @"0",@"0",@"0",@"0",@"0",nil], [NSMutableArray arrayWithObjects: @"0",@"0",@"0",@"0",@"0",nil], [NSMutableArray arrayWithObjects: @"0",@"0",@"0",@"0",@"0",nil],nil];
[[tiles ObjectAtIndex:1] ReplaceObjectAtIndex:1 withobject:@"1"];
它确实可以编译,但出现错误:“NSMutableArray 可能无法响应 ObjectAtIndex:”,在这一行:
[[tiles ObjectAtIndex:1] ReplaceObjectAtIndex:1 withobject:@"1"];
显然这是行不通的。
这只是语法问题吗?还是有什么事情做不到?
谢谢。
I'm having problem with replacing objects inside NSMutableArray which is an object inside another NSMutableArray.
In the interface:
NSMutableArray *tiles;
In the implementation:
tiles = [[NSMutableArray alloc] initWithObjects:
[NSMutableArray arrayWithObjects: @"0",@"0",@"0",@"0",@"0",nil],
[NSMutableArray arrayWithObjects: @"0",@"0",@"0",@"0",@"0",nil],
[NSMutableArray arrayWithObjects: @"0",@"0",@"0",@"0",@"0",nil],nil];
[[tiles ObjectAtIndex:1] replaceObjectAtIndex:1 withobject:@"1"];
It does compile but with an error: "NSMutableArray may not respond to ObjectAtIndex:", on this line:
[[tiles ObjectAtIndex:1] replaceObjectAtIndex:1 withobject:@"1"];
Obviously it does not work.
Is it just a syntax problem? Or is it something can't be done?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 objectAtIndex (用小写 o 表示对象)。
try with objectAtIndex (with a lowercase o for object).