我正在使用下面的代码
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(processTap)];
- (void) processTap
{
//do something
}
但是我需要发送数据到processTap函数。反正有这样做吗?
最佳答案
示例:
UIImageView *myPhoto = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"tab-me-plese.png"]];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(processTap:)];
[myPhoto setTag:1]; //set tag value
[myPhoto addGestureRecognizer:tap];
[myPhoto setUserInteractionEnabled:YES];
- (void)processTap:(UIGestureRecognizer *)sender
{
NSLog(@"tabbed!!");
NSLog(@"%d", sender.view.tag);
}