Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between removeFromSuperview and .hidden for an imageview

Tags:

ios

uiview

Is there a difference between removeFromSuperview and .hiddenproperty for an imageview?

They both seem to just hide the imageview. I would like to completely remove the imageview under certain circumstances.

like image 897
dev_help Avatar asked Aug 12 '14 19:08

dev_help


2 Answers

removeFromSuperview

  1. Removes the object from its parent view, thus 'hiding' it in a sense.
  2. Removes any constraints tying the view to its parent view or other sibling views
  3. Implicitly removes the retain count of a view, potentially causing an object to be deallocated if nothing else has a reference to the object

hidden

  1. Makes the view hidden
  2. The view is still part of layout
like image 83
Acey Avatar answered Sep 23 '22 15:09

Acey


Hidden makes the view hidden/untouchable - it's akin to making the alpha equal to 0.

removeFromSuperview removes the view completely from its superview.

The two are pretty different, so it really depends on what you want. If you plan on temporarily hiding the view, then making it hidden is probably what you want. If you want to remove it and have no plans on adding it again (at least within the view controller's lifecycle), then removeFromSuperview is better.

like image 34
Vadoff Avatar answered Sep 19 '22 15:09

Vadoff