I am trying to manage a few animations in my scene using the following method:
-
In a loop, create animated
UIImageView, set the on stopped
method. Also, store this UIImageView
in a NSMutableDictionary. The animation ID is the same as the key in the dictionary. -
When this animation is stopped, get the animation ID. Use [animations objectForKey: animationID] to get the imageview object. I remove the imageview from the superview and release it. I also remove the object from the dictionary using the key.
-
Create another animated object, rinse, repeat.
The problem is, when I go to get the object based on the key, NULL is returned. I assume this is related to how the dictionary works– it copies the values instead of retaining them. Because it is copied, I can’t actually remove that object.
How can I get NSDictionary to NOT copy these objects (so I have the original) or how do I release these animated objects and remove them from the superview when they are done animating?
NSDictionary doesn’t copy objects (only keys). The only reason you’d be getting NULL back is if you supply the wrong key, or the object has already been removed.
It isn’t 100% clear from your description, but you seem to suggest that you “2. … remove the object from the dictionary …” and then later “… got to get the object …”. If these are two separate activities, then you most certainly won’t find the object there on the second visit.