问题
I have a NSMutableArray that is loaded with values.
Later in the application, I need to change the values of one of the elements in the array.
How do I accomplish this?
thanks tony
回答1:
Take a look at the class reference instance methods:
http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSMutableArray_Class/Reference/Reference.html
You can use:
replaceObjectAtIndex:withObject:
given you know the index of the object.
replaceObjectsAtIndexes:withObjects:
to replace multiple objects at once.
回答2:
Call -[NSMutableArray replaceObjectAtIndex:withObject:]
. Or, if the object in the array is mutable, just grab it with -objectAtIndex:
and modify its properties directly.
回答3:
You would probably want to use 'replaceObjectAtIndex:withObject:' for replacing the object itself.
回答4:
refer following link. It may help you
http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSMutableArray_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableArray/replaceObjectAtIndex:withObject:
From that you can use replaceObjectAtIndex:withObject: or
replaceObjectsAtIndexes:withObjects: for replacing objects.
just you have to know the index of objects.
来源:https://stackoverflow.com/questions/4218256/change-a-value-within-a-nsmutablearray