0

5 つのオブジェクトを持つ NSMutableArray があります

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

次のコード行を実行した後:

[self.gameComponents removeObjectAtIndex:0];

単にインデックス 0 のオブジェクトを削除し、すべてをインデックス上にスライドさせる代わりに、私は期待していました。インデックス [0] のオブジェクトは nil に設定され、インデックス [4] のオブジェクトは削除されます。

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

私にはかなり困惑..

4

1 に答える 1

-4

次のコード行を使用します

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

コードの 1 行目はオブジェクトを のシングルトン インスタンスに置き換え、コードNSNullの 2 行目は配列から最後のオブジェクトを削除します。

于 2013-08-15T02:31:41.010 に答える