我的代码是:
[[arrayOne objectAtIndex:indexSelected] replaceObjectAtIndex:1 withObject:new];
NSLog(@"indexSelected:%d", indexSelected); // = 0
NSLog(@"new:%@", new); // = 26
indexSelected
是一个整数,new
是一个字符串
当我尝试执行此操作时,出现异常:Termating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x1cee60'
为什么?
最佳答案
这是因为 NSArray 是不可变的。使用 NSMutableArray。
关于objective-c - iOS:替换数组数组中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6296398/