我有几个 UIImageView,每个都有一个标签;我有一个图像数组,我想做的是:当用户点击其中一个 UIImageView 时,应用程序会从数组中返回某个图像。
我这样实现:
- (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 ?谢谢阅读^_^