views:

250

answers:

2

quick question...

I have a series of buttons, each with a tag. I click the buttons which individually create a uiimageview based on the tag number. So this tag number, say 43 is passed and a new uiimageview is created using 43.png

All this is working nicely and I can remove the created images by clicking on them...

..but... I'm now wondering how I can remove all these created images all at once. So I have say 4 images which were all created as a result of clicking the buttons.

my question is this: can I use a string to identify these "created" images some how? I thought about using a tag for them starting with 99 maybe? so 991, 992, 993 etc. but this doesn't seem like good coding. In the past, and indeed in Flash, I used a tag of item1, item2... then in the code, I simply loop through ALL tags on the screen starting with "item" and remove them.

any ideas on the best way to tackle this??

Thanks

A: 

You could simply store a reference to all the created images as elements in an array kept as an attribute of the viewController.

Alternatively, this is the sort of problem that can be handled with a subclass. You can just create a subclass of UIImage with some sort of identifier attribute and use that to remove them.

TechZen
storing them as I add them does sound like the best idea. so if I add each uiimage created to some sort of array, I can then just loop through that array and reference each uiimage to then remove?
Matt Facer
A: 

Seems like you could just loop through the subviews array, look at the tag property of each one, convert each to a string, and use NSString startsWith: to remove those that match your pattern.

But I think it would be easier to just keep your own list of created images, and delete them when desired.

Kristopher Johnson
this is what I imagined I'd have to do... a tag must be an integer then? Think I have tried once with a string which obv. didn't work!
Matt Facer
Yes, tags are integers.
Kristopher Johnson