我正在向一些滚动视图动态添加图像按钮。它们都指向一个长按处理程序。现在,我如何知道哪个按钮被按下了?[sender tag]给出了我添加到按钮的长按手势识别器的标记,我无法手动设置该标记。
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?
}
recognizer.view.tag
给我错误的 UIButton 点击标签。有什么解决办法吗? - rohan-patel