What is the best way to remove all subviews from you self.view?

user440096 picture user440096 · Aug 9, 2012 · Viewed 44.3k times · Source

I was thinking maybe something like this might work:

    for (UIView* b in self.view.subviews)
    {
       [b removeFromSuperview];
    }

I want to remove every kind of subview. UIImages, Buttons, Textfields etc.

Answer

Max picture Max · Aug 9, 2012
[self.view.subviews makeObjectsPerformSelector: @selector(removeFromSuperview)];

It's identical to your variant, but slightly shorter.