Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BarryK88

macrumors member
Original poster
Mar 1, 2011
31
0
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:

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

thanks in advance!
 
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:

Code:
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).
 
this function did the job:

Code:
[scroller.subviews containsObject:image];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.