I have an UIImageViews with userInteractionEnabled, and i want to know with image i currently tap. What i should do to know that? I have a poster wall and class for that ThumbPosterModel there i have all poster information with i want to pass through.
So my code is:
for (ThumbPosterModel *tPoster in _thumbsPosterStack) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:tPoster.thumb];
imageView.userInteractionEnabled = YES;
imageView.frame = CGRectMake(i, imageView.frame.origin.y, imageView.frame.size.width, imageView.frame.size.height);
[_posterWallScrollView addSubview:imageView];
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
[imageView addGestureRecognizer:tap];
}
And then i have:
-(IBAction)imageTapped:(id)sender {
//something do here, but know i don't know what.
}
Should i subclass UIImageView that should contains all ThumbPosterModel params? I don’t think it is good idea, but i can’t figure any other solution.
Ok this is very simple just add
tagproprty of each image with appropriate and distinct value other then0and use that proprty to identify the image 🙂Happy Coding 🙂