PDA

View Full Version : How to check if an image is within a particular subview.




BarryK88
Apr 13, 2011, 08:05 AM
I've got several images inside a scrollview and within my normal view. I'd like to check by means of an "if statement" if this image is inside my scrollview or not.

i put my images inside the scroller with:

[scroller insertSubview:image belowSubview:self.view];

thanks in advance!



robbieduncan
Apr 13, 2011, 08:19 AM
Images can't be inserted into views as subviews. UIImageViews, however, can. This is a significant difference.

Are you wanting to check if a specific UIImageView is already added as a subview or if a UIImageView containing a specific image is already added?

If it's the latter you will have to first explain how two images will be considered unique. For example:


UIImage *image1 = [UIImage imageNamed:@"MyImage.png"];
UIImage *image2 = [UIImage imageNamed:@"MyImage.png"];

if (image1 != image2)
{
NSLog(@"Different images");
}


will log "Different images" despite both being created from the same image: it is up to you to write the code required to track which image came from which file (or which URL or whatever your image source is).

BarryK88
Apr 15, 2011, 03:18 AM
this function did the job:

[scroller.subviews containsObject:image];