bas bas - 1 year ago 161
iOS Question

Performance of UIView: removeFromSuperview VS hide

This question is really basic. What is the performance difference between removing a

from the view hierarchy and hiding a

I have read that Views that are not needed should be removed from the view hierarchy. I currently have the situation that a
should sometimes be visible. When do I hide the
and when do I remove it from it's superview?

Is it expensive to change the view hierarchy?

Answer Source

If you need to alternate between showing and hiding the subview, the best approach is definitely hiding it. For a UIButton the memory implications are not that great anyway. And the code is certainly simpler if you just switch the hidden property.

Also, you get the additional advantage that the hidden property is animatable!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download