I have several UIImageView, each of which has a tag; and I have an array of images, what I want to do: when the user clicks one of the UIImageView, the application returns a specific image from the array.
i implement 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 {
I want to know imageView.tag and pass imageView.tag to
UIImageView *tappedImage = [imageArray objectAtIndex:imageView.tag];
to display the image.
I marked them all, the question is, how can I recognize the tag image that I click? thanks for reading ^ _ ^
iphone tags uigesturerecognizer
flutewang
source share