[英]iPhone UIButton Tap
I am trying to make a button that response to single and double tap. 我正在尝试创建一个按钮,以响应单击和双击。 I am trying to do this using myAction method.
我正在尝试使用myAction方法执行此操作。 The problem is that first time when I press the button the method myAction isn't called.
问题是,当我第一次按下按钮时,不会调用myAction方法。
Can somebody tell why this happening and how can I fix that? 有人可以告诉我为什么会这样吗,我该如何解决?
-(IBAction)myButton:(id)sender{
UIButton *theButton = (UIButton *)sender;
[theButton addTarget:self action:@selector(myAction:forEvent:) forControlEvents:UIControlEventAllEvents];
}
- (void)myAction:(id)sender forEvent:(UIEvent *)event {
NSLog(@"Touch events goes here");
}
Thank you, 谢谢,
I. Vasilev 瓦西廖夫
I assume that you link the event with myButton:sender 我假设您将事件与myButton:sender链接
So, it simply means: 因此,它只是意味着:
When tap at myButton, register `myAction` to the button's event handler.
You can fix this by call myAction directly or, just relink the event to myAction: instead. 您可以通过直接调用myAction来解决此问题,或者只需将事件重新链接到myAction:即可。
You should define the functions in your header file("MyViewController.h, for example"). 您应该在头文件中定义函数(例如“ MyViewController.h”)。
@interface bla bla {
}
- (IBAction)myButton:(id)sender;
- (void)myAction:(id)sender forEvent:(UIEvent *)event;
@end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.