Code Code - 2 months ago 11
iOS Question

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

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.

Max Max
Answer
[self.view.subviews makeObjectsPerformSelector: @selector(removeFromSuperview)];

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

Comments