iphone - NSMutableArray removeObjectAtIndex 导致错误

标签 iphone objective-c nsmutablearray

<分区>

这可能是一个简单的问题,但是好心的人可以给我提示以下情况中出了什么问题吗,我只是不明白。我有一个 NSMutableArray“playerArray”,它有对象“零”、“一”、“二”、三。

我试图删除“行”处的对象,但它不起作用。会不会因为它不响应 removeObjectAtIndex 而导致异常似乎被抛出,因此它返回一个不可变数组?

 NSUInteger row = 1; // [indexPath row];
 NSLog(@"playerArray:%@", playerArray);
 NSLog(@"row: %i", row);
 [playerArray removeObjectAtIndex:row];  

结果是:

playerArray:(
ZERO,
ONE,
TWO,
THREE
)
2010-11-21 20:58:46.681 FamQuiz_v2[2166:207] row: 1
2010-11-21 20:58:46.682 FamQuiz_v2[2166:207] -[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x5e3b9a0
2010-11-21 20:58:46.683 FamQuiz_v2[2166:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x5e3b9a0'

最佳答案

看起来你的数组实际上并不是一个 NSMutableArray。通过记录类名来验证它:

NSLog(NSStringFromClass([playerArray class]));

或者,检查:

if ([playerArray isKindOfClass: [NSMutableArray class]])
{
...
}

关于iphone - NSMutableArray removeObjectAtIndex 导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4240145/

相关文章:

iphone - 真假 : There is no way to set the file owner of a cell loaded using registerNib:forCellReuseIdentifier:

iphone - ViewDidLoad() 中的调用方法

objective-c - 如何将 UITableViewCell 中的按钮与其操作方法连接起来

objective-c - NSArray 深拷贝导致崩溃

iphone - Iphone App在4.0或更低版本的SDK上崩溃

ios - 通过动画调整 UIView 大小时约束不起作用

ios - 在 UIPickerView 上选择后显示整个数字值?

objective-c - 更改 NSOpenPanel 按钮文本

objective-c - 返回可变对象与返回不可变(非成员)对象

ios - 从数组中获取内容并在 UILabel 中显示