我有一个 NSMutableArray,我需要碰碰它的值,但我有这个错误:
[__NSArrayI replaceObjectAtIndex:withObject:]: 无法识别的选择器发送到实例 0x5291db0
这是我的 NSMutableArray 的声明:
NSMutableArray *selectedOptions = [NSArray arrayWithObjects:[NSNumber numberWithInteger:0], nil];
然后,我使用 replaceObjectAtIndex 方法,方法如下:
[self.selectedOptions replaceObjectAtIndex:0 withObject:[NSNumber numberWithInteger:1]];
但是我得到了那个错误,我正在使用 NSMutableArray。
谢谢
最佳答案
您正在创建一个常规的非可变 NSArray
。你的代码应该是
NSMutableArray *selectedOptions = [NSMutableArray arrayWithObjects:[NSNumber numberWithInteger:0], nil];
Objective C 非常动态,所以它不会在编译时捕获这个错误。
关于objective-c - [__NSArrayI replaceObjectAtIndex :withObject:]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14371152/