views:

37

answers:

2

How can i remove an ImageView added on a dynamically created UIView, so that i can add another ImageView on my UIView.

+4  A: 

You either add a tag for that UIImageView and find it based on tag or loop throughout the subviews and look for an object of class UIImageView containing the image you need to change.

Paul Ardeleanu
+1  A: 

Easiest way is probably with tags. So...

UIImageView *removeMe = [[UIImageView alloc] init];
removeMe.image = [UIImage imageNamed:@"theImage.png"];
removeMe.tag = 1;
[theView addSubview:removeMe];
[removeMe release]; //theView now retains it!

...then later:

UIImageView *removalTarget = (UIImageView *)[theView viewWithTag:1];
[removalTarget removeFromSuperview];
Dan Ray