Iphone – remove all objects from a uiview

iphoneuiview

I have a UIview which I am drawing a series of buttons on to. I want to change these buttons depending on a selection the user makes. This is working nicely… but I cannot remove the buttons which were already there.

It's a UIScrollView with a view added as a subview. It's the subview which I need to basically "clear" / wipe clean. In Interface builder there is nothing on that view. I simply add it in my code.

I've been looking around and have looked at doing subViewcontroller setNeedsDisplay, but nothing's working.

any ideas? thanks for any help.

Best Answer

I've actually figured out how to do what I needed... but I'd still be keen to see what people suggested.

I wanted to remove all the buttons in my view which was assigned to the UIScrollView. I KNOW they are only buttons being added, so I just looped through them all removing them one by one.

for (UIButton *aButton in [viewBasicItems subviews]) {
    [aButton removeFromSuperview];
}
Related Topic