You have to know that in iOS you are manipulating "views". Views are UI parts (images, labels, inputs etc.) or a containing layer.
At the launch beginning you MUST add a view to you window. Then you can add add as many views your want on your view.
If you add a view B on a view A. And the view A on the window.
Semantic is :
- View A is the superview of B
- View B is a subview of A
- View A is a subview of the window
The window is the superview of view A
So if you invoke removeFromSuperview on B, you removing B to be on A (and to be displaying).
Please note :
When you add a subview (addSubview:) a retain is performed on the view added.
When you remove a view (removeFromSuperview: or removeSubviewAtIndex:) a release is performed on the view removed.
To answer to you initial question
for (UIView *oldViews in cell.contentView.subviews)
{
[oldViews removeFromSuperview];
}
Perform the removeFromSuperview method on every cell.contentView subviews.
So old views are removed from the screen but not necessary deallocated (they are released so retainCount - 1).