if([imageview superview])
{
[imageview removeFromSuperview];
[myView 开发者_开发知识库addSubview:imageview];
}
else if([imageview superview])
{
[imageview removeFromSuperview];
[myView addSubview:imageview];
}
else if([imageview superview])
{
[imageview removeFromSuperview];
[myView addSubview:imageview];}
Here I dynamically create multiple imageviews and set tag values and add it as a subview to the UIView. I need to identify which imageview is in superview position and remove it and add another by tapping it.
if you want to get your image view by its tag value then you can :
UIImageView *tempView = [self.view viewWithTag:yourTag];
make sure your tag value is valid id for the image view.
Hope it gives you an idea...
UIImageView* tempView = (UIImageView*)[self.view viewWithTag:yourImageViewTag];
if([tempView superview])
[tempView removeFromSuperview];
精彩评论