[UIView removeFromSuperview] also recursively removes the recursive representations of its children?

I have a view hierarchy that I need to completely remove. Is it possible to just call removeFromSuperview in the top parent view, or do I need to recursively visit each child element of the node and delete it separately?

Edit : just to clarify, I understand that removing a parent physically removes the children from the view, but does it also reduce their number of links accordingly?

+4
source share
4 answers

All submissions relate to the submission; therefore, when you delete a view from it, the supervisor - it is deleted with all its subviews.

+4
source

Yes. You can view representations as a tree structure. Therefore, if you specify that the view will be removed from the super view, the entire structure will be deleted.

For example: A UIButton is actually a view containing a UILabel that displays the name of the button. So you can do it [myUIButton removeFromSuperview]; , which will remove the button and its own hierarchy of views (including the button containing the UILabel).

Note If you only want to hide / show the view, you can also set its hidden property to YES or NO instead of removing the view from the view hierarchy. Thus, it is easy to display the view again.

+2
source

No, deleting a view does nothing for it as child views (but, of course, they will no longer be drawn because they are no longer in the view hierarchy).

Of course, if you delete a view and do not have other strong references to it, it may be released at some point in the future (although you should not do this or assume that there are no other links). When and if it is released, it will remove the child views and release them.

+2
source

You can do this on the top parent view.

0
source

Source: https://habr.com/ru/post/1383080/


All Articles