【发布时间】:2023-03-29 23:17:01
【问题描述】:
我正在向某些滚动视图动态添加图像按钮。它们都指向一个 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?
}
【问题讨论】:
标签: iphone cocoa-touch button tags sender