0
我有一个数组列表,其中的每个元素都是数组。我知道,这有点怪异,但它是必要的。所以,我需要替换最深的数组元素。我试过这个:Array-within-array项目替换
for (int i = 0; i < [myArray count]; i++) {
for (int j = 0; j < [[myArray objectAtIndex:i] count]; j++) {
for (int k = 0; k < [[[myArray objectAtIndex:i] objectAtIndex:j] count]; k++) {
[[[myArray objectAtIndex:i] objectAtIndex:j] replaceObjectAtIndex:k withObject:@"Some_string"];
}
}
}
并且得到了一个错误*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance
。但我可以记录这个元素,例如NSLog(@"%@", [NSString stringWithFormat:@"%@",[[[myArray objectAtIndex:0] objectAtIndex:0]objectAtIndex:0]]);
,没关系。
它可能是什么?谢谢你的帮助。
是的。我应该将其转换为NSMutableArray?更新:我通过'NSMutableArray * myMutArray = [myArray mutableCopy]'从myArray创建可变数组,但它没有帮助。 – Akki 2011-12-27 15:56:06
你能表达一下自己吗? – LordTwaroog 2011-12-27 15:57:16
我认为问题是你需要内部数组可变。因此,不是[myArray mutableCopy]执行'myMutArray = [NSMutableArray array]',然后通过myArray并为每个子数组添加它的mutableCopy到新的'myMutArray'。 – mrueg 2011-12-27 16:06:30