When my app gets back to it's root controller, in the ViewDidAppear I need to remove all subviews.
How is this done?
When my app gets back to it's root controller, in the ViewDidAppear I need to remove all subviews.
How is this done?
You can use the convenient mehtod makeObjectsPerformSelector:
as follows:
NSArray * subviews = [self.view subviews];
[subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
Note: This will remove every view that your main view contains and release them, if they are not retained elsewhere. From Apple's documentation on removeFromSuperview:
If the receiver’s superview is not nil, this method releases the receiver. If you plan to reuse the view, be sure to retain it before calling this method and be sure to release it as appropriate when you are done with it or after adding it to another view hierarchy.
Get all the subviews from your root controller and send each a removeFromSuperview:
NSArray *viewsToRemove = [self.view subviews];
for (UIView *v in viewsToRemove) {
[v removeFromSuperview];
}