开发者

Deleting a UIImageView

So what I want to do is if image1 collides with image2, I want to remove image1 from the screen (not just hide it but remove it) in a way that the appli开发者_如何学编程cation does not crash or use to much memory.

I think it's something related with release but I'm not sure. How can I do this, please?


remove it from the superview

[image1 removeFromSuperview];

EDIT:

if you have a pointer to image1, you might have just added it to the superview and did not release it yet. So, if that is the case and to avoid any leaks, just release it when removing it from superview.

[image1 removeFromSuperview]; [image1 release], image1 = nil;


Just remove it from your superview:

[image1 removeFromSuperview];

If you've managed your memory correctly heretofore, you won't need to release it at this point. Here are a few scenarios:

  1. Your class does not own a reference to image1 (i.e. it's not a property). So, when you created image1 and added it to your view, you made sure to autorelease it. As such, the view holds the owning reference; when it is removed from that view, the view will release it.

  2. Your class does own a reference to image1 (i.e. it is a property). In -dealloc, you have released image1 according to the Objective-C memory management idiom, so when you remove it from the superview, you still don't need to perform memory management.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜