ボタンがあります。ユーザーがクリックするたびに、アプリケーションはUIImageView (imageview) をインスタンス化し、そのタグに一意の番号を割り当てます。
- (IBAction)buttonClicked:(id)sender {
imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 240)];
NSUInteger currentag = [self UniqueNum]; // Assigning a unique number to the tag variable
[self.view addSubview:imageview];
imageview.backgroundColor = [UIColor blueColor];
imageview.userInteractionEnabled = YES;
imageview.tag = currentag;
}
私の目標は、ユーザーが触れた UIImageView コピーのタグ番号を取得することです。次のコードで、実際に取得するのは、アプリケーションが最後に作成した UIImageView コピーのタグ番号です。アプリケーションがタッチされたオブジェクトのタグ番号を指すようにするにはどうすれば改善できますか?
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [[event allTouches] anyObject];
if([touch view] == imageview) {
NSLog(@"Tag: %i",imageview.tag);
}
}
ご協力ありがとうございました。