NSMutableArray removeObjectAtIndex删除两个对象

时间:2013-08-15 02:26:37

标签: ios objective-c nsmutablearray

我有一个带有5个对象的NSMutableArray

[0] StateGeographicComponent *  0x0a455ba0
[1] StateGeographicComponent *  0x11c374b0
[2] StateGeographicComponent *  0x08e5f720
[3] StateGeographicComponent *  0x11c15430
[4] StateGeographicComponent *  0x0a458f20

执行以下代码行后:

[self.gameComponents removeObjectAtIndex:0];

而不是简单地删除索引0处的对象,并按照我的预期将所有内容向上滑动。 index [0]处的对象设置为nil并删除索引[4]处的对象。

[0] id  0x00000000
[1] StateGeographicComponent *  0x11c374b0
[2] StateGeographicComponent *  0x08e5f720
[3] StateGeographicComponent *  0x11c15430

让我感到非常困惑..

1 个答案:

答案 0 :(得分:-4)

使用以下代码行

[self.gameComponents replaceObjectAtIndex:0 withObject:[NSNull null]];
[self.gameComponents removeLastObject];

第一行代码用单例实例NSNull替换对象,第二行代码从数组中删除最后一个对象。

相关问题