I have multiple ImageViews in a UIScrollView and I want to identify the specific imageView on which I touched. So that I could do some actions. (for example, showing Alert with the image name).
I have seen some similar posts, but they did not have proper answer. And some answers were complex to me as I am pretty new to iPhone programming.
It would be great, If anybody helps with a simple example. :-)
my code is like this
- (void)viewDidLoad {
imgScrollView.userInteractionEnabled =YES;
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= 5; i++)
{
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// setup each frame to a default height and width
CGRect rect = imageView.frame;
rect.size.height = kHeight;
rect.size.width = kWidth;
imageView.frame = rect;
imageView.tag = i;
[imgScrollView addSubview:imageView];
[imageView release];
}
[self layoutImages];
[super viewDidLoad];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
// WHAT CODE SHOULD I GIVE HERE ?????????? :-)
}