我正在动态地将图像按钮添加到一些滚动视图中。它们都指向一个 longPressHandler。现在,我如何知道按下了哪个按钮?[sender tag] 给了我添加到按钮的 longGestureRecognizer 的标签,我无法手动设置该标签。
for (...) {
UIButton *button = [[UIButton alloc] init];
button.tag = w + h * 3;
[button addTarget:self action:@selector(imageButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UILongPressGestureRecognizer *gest = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(imageButtonLongPress:)];
gest.minimumPressDuration = 1;
gest.delegate = self;
[button addGestureRecognizer:gest];
[gest release];
[scrollView addSubview:button];
[button release];
}
- (void) imageButtonLongPress:(id)sender {
// how to get button tag here?
}