多次点击 UIButton 并访问 Button 的不同行为

发布于 2024-12-25 20:46:07 字数 856 浏览 0 评论 0原文

我创建了一个多用户项目,可以点击不同的按钮。

以下问题可能会出现阶段, 我实现了 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,

enter image description here
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤芳又自赏 2025-01-01 20:46:07

如果按钮是 UIButton 的实例,那么您根本不需要使用gestureRecognizer。
尝试设置 addTarget:action 以在用户单击该 UIButton 时获取回调:

[button1 addTarget:self action:@selector(btnPress:)];
[button2 addTarget:self action:@selector(btnPress:)];

如果您已经为每个按钮设置了标记值,那么您的 IBAction 方法将正常工作。

-(IBAction)btnPress:(id)sender{
NSInteger tag=[sender tag];
NSLog(@"%d",tag);
}

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:

[button1 addTarget:self action:@selector(btnPress:)];
[button2 addTarget:self action:@selector(btnPress:)];

If you have already set tag value to each button, then your IBAction method would work properly.

-(IBAction)btnPress:(id)sender{
NSInteger tag=[sender tag];
NSLog(@"%d",tag);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文