私はいくつかのUIImageViewを持っており、それぞれにタグがあります。画像の配列があります。ユーザーがUIImageViewの1つをタップすると、アプリは配列から特定の画像を返します。
私はこのように実装します:
- (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?
}
を見つけて、imageView.tag
に渡しimageView.tag
たい
UIImageView *tappedImage = [imageArray objectAtIndex:imageView.tag];
画像を表示します。
tag
それらすべてにタグを付けました。問題は、タップしているimageViewをどのように見つけることができるかということです。読んでくれてありがとう^_^