i have several UIImageView, each of them has a tag; and I have an array of Images, what i want to do is: when user tap one of the UIImageView, the app give back the certain Image from array.
i implement like this:
- (void)viewDidLoad
{
[super viewDidLoad];
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:scroll];
NSInteger i;
for (i=0; i<8; i++)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, i*100 + i*15, 300, 100)];
imageView.backgroundColor = [UIColor blueColor];
imageView.userInteractionEnabled = YES;
imageView.tag = i;
NSLog(@"%d", imageView.tag);
[scroll addSubview:imageView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(findOutTheTag:)];
[imageView addGestureRecognizer:tap];
}
scroll.contentSize = CGSizeMake(320, 115*i);
}
- (void)findOutTheTag:(id)sender
{
// HOW TO FIND THE tag OF THE imageView I'M TAPPING?
}
I want find out the imageView.tag
, and pass imageView.tag
to
UIImageView *tappedImage = [imageArray objectAtIndex:imageView.tag];
to display the image.
I did tag all of them, question is how I can find out the tag
of the imageView I'm tapping? thank you for reading ^_^
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…