开发者

Access UIView after adding it to superview/as a subview

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 开发者_如何学Gothe top of each other. Ideally I'd like them to appear in a stack. Any ideas how I might do that?

Thanks :)


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

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

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜