我的目标是简单地将正确的发送button.titleLabel.text
到我的视图控制器的 handleLongPress 函数。这是我的功能:
- (IBAction)handleLongPress:(UILongPressGestureRecognizer *)sender {
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.0;
[self setUserIntendsToChangeUIsoTheUIisLockedUntilUserSelection:YES];
NSLog(@"sender? %@", sender);
if ([sender.view isKindOfClass:[UIButton class]]) {
self.myButton = (UIButton *)sender.view;
NSLog(@"!!!!! %@", self.myButton.titleLabel.text);
[self.view addSubview:self.scrollPickerView];
}
}
这是我的故事板,我创建了一个引用出口集合的按钮“H”、“Cl”、“C”等。
每个按钮都会响应UILongPressGesture
,但记录的消息NSLog(@"!!!!! %@", self.myButton.titleLabel.text);
始终引用相同的 UIButton“C”,即使我按住不同的按钮也是如此。我做错了什么?如何让每个按钮将其标题发送到 handleLongPress 函数?