views:

98

answers:

1

Hi, I have a variable sized array of UIImageViews that I'd like to add to my main View. So I loop through the array, adding each UIImageView to the scene as follows:

for (UIImageView *nextImageView in myImageArray]
    [self.view addSubview:nextImageView];

(I also configure their frames individually but have left that out here)

However, I later want to remove these UIImageViews. But how can I access them? I'm aware of the tag property, and that I could tag each one as I add it, and then remove views of the same tag, however I'm also adding and removing other elements to the view which messes up the index, and it doesn't seem like a very foolproof solution.

I thought of having a single UIView property in my class, and adding the array of UIImageViews as subviews of this main view, like so:

for (UIImageView *nextImageView in myImageArray]
    [holderView addSubview:nextImageView];

Then I can remove all the images by calling:

[holderView removeFromSuperview];

However, I'm not sure how to arrange the UIImageViews within the UIView. If I try to configure their frames individually, they don't appear. So at the minute they just draw over the top of each other. Ideally I'd like them to appear in a stack. Any ideas how I might do that?

Thanks :)

A: 

I believe you could iterate the array of UIImageViews and call removeFromSuperview

for (UIImageView *nextImageView in myImageArray]
    [nextImageView removeFromSuperview];

Hope this helps.

Florin
*smacks head with palm* For some reason I didn't think of that, despite using it in the past. Thanks!
Smikey