如何从数组中删除对象?

1 iphone cocoa objective-c

我想知道你是如何从a中删除对象的NSMutableArray,因为我现在使用[astroids removeFromSuperview];但是它只是在屏幕上删除了图像,但实例本身即使在删除时仍然存在.

Sea*_*phy 14

-removeFromSuperview是一种方法UIView,而不是NSMutableArray.似乎UIView你正在调用的实例也保存在MSMutableArray.您将需要使用其中一种NSMutableArray方法来删除阵列本身上的对象.

有必要单独删除数组,因为它还拥有相关对象,并保留它独立于其他地方的使用.

NSMutableArray删除对象的方法:

– removeAllObjects  
– removeLastObject  
– removeObject:  
– removeObject:inRange:  
– removeObjectAtIndex:  
– removeObjectsAtIndexes:  
– removeObjectIdenticalTo:  
– removeObjectIdenticalTo:inRange:  
– removeObjectsFromIndices:numIndices:  
– removeObjectsInArray:  
– removeObjectsInRange:
Run Code Online (Sandbox Code Playgroud)

请参阅http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsmutablearray_Class/index.html