多次点击 UIButton 并访问 Button 的不同行为
我创建了一个多用户项目,可以点击不同的按钮。
以下问题可能会出现阶段, 我实现了 gestureRecognizer 并且它是正确的工作,但是如何让用户点击哪个按钮来访问这些按钮事件的
以下屏幕显示按钮,
以下是gestureRecognizer委托方法的代码,如何获取按钮事件以及如何管理它,
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isKindOfClass:[UIButton class]]) {
NSLog(@"Button is pressed");
if (tag == 1) {
NSLog(@"Button1 is pressed");
}
return NO;
}
return YES;
}
以下是点击按钮时IBAction方法触摸的方法
-(IBAction)btnPress:(id)sender{
tag=[sender tag];
NSLog(@"%i",tag);
}
,但这里的问题是首先调用gestureRecognizer委托方法,然后调用IBAction方法如何解决这个问题,
提前感谢您在我的问题上花费宝贵的时间,
谢谢并致以问候 霓虹塞缪尔.
I create a project of the Multiple user can tapped on the different button.
Following problem may phase,
I implement the gestureRecognizer and it's proper work but how get the which button tapped by the user for that to access those button event's
following screen shows the button,
Following is the code for gestureRecognizer delegate method so, how to get the button event and how to manage it,
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isKindOfClass:[UIButton class]]) {
NSLog(@"Button is pressed");
if (tag == 1) {
NSLog(@"Button1 is pressed");
}
return NO;
}
return YES;
}
following method for the IBAction method to touch when the button tapped
-(IBAction)btnPress:(id)sender{
tag=[sender tag];
NSLog(@"%i",tag);
}
But here issue is first call the gestureRecognizer delegate method then IBAction method to how to solve this problem,
Thanks in advance for your valuable time spend on my problem,
Thaks and regards
Neon Samuel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果按钮是 UIButton 的实例,那么您根本不需要使用gestureRecognizer。
尝试设置 addTarget:action 以在用户单击该 UIButton 时获取回调:
如果您已经为每个按钮设置了标记值,那么您的 IBAction 方法将正常工作。
If the button is instance of UIButton, then you do not need to use gestureRecognizer at all.
Try to set addTarget:action to get callback when user click that UIButton:
If you have already set tag value to each button, then your IBAction method would work properly.