【发布时间】:2014-08-17 18:19:14
【问题描述】:
我的目标是简单地将正确的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 函数?
【问题讨论】:
标签: objective-c ios7 uigesturerecognizer iboutletcollection