tags:

views:

118

answers:

1

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.

+1  A: 

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];
}
Matt Facer
Without losing any generality, you can do `for (UIView *view in [.. subviews]) { ... }` (this is actually the correct way according to the documentation).
Adam Woś
great - thank you!
Matt Facer