禁用 IBAction 链接按钮

发布于 2024-11-24 03:11:43 字数 479 浏览 2 评论 0原文

我使用 Interface Builder 创建了一个按钮并将其链接到一个操作。我想禁用下面 if 语句中的 hit 按钮。

- (IBAction)hit:(id)sender {
    Application *app = [[Application alloc] init];
    int nc = [app dealCard];
    [userOne setIntValue:tu];
    [userTwo setIntValue:nc];
    tu += nc;
    [totalUser setIntValue:tu];
    BOOL bust = [app checkBust:tu];
    if (bust == YES) {
        [console setIntValue:1];
        //Disable button here.
    }
}

我应该怎么办?

I made a button using Interface Builder and linked it to an action. I'd like to disable the hit button on the if statement below.

- (IBAction)hit:(id)sender {
    Application *app = [[Application alloc] init];
    int nc = [app dealCard];
    [userOne setIntValue:tu];
    [userTwo setIntValue:nc];
    tu += nc;
    [totalUser setIntValue:tu];
    BOOL bust = [app checkBust:tu];
    if (bust == YES) {
        [console setIntValue:1];
        //Disable button here.
    }
}

What should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

高跟鞋的旋律 2024-12-01 03:11:43

UIButtonUIResponder 的子类,它具有 enabled 属性。将其设置为 NO 以禁用按钮的操作。例如

UIButton *theButton = (UIButton *)sender;
theButton.enabled = NO;

UIButton is a subclass of UIResponder which has an enabled property. Set this to NO to disable the action from the button. E.g.

UIButton *theButton = (UIButton *)sender;
theButton.enabled = NO;
断舍离 2024-12-01 03:11:43

我发现了问题。事实证明,我使用的是 NSButton 而不是 UIButton,因此我将声明更改为:NSButton *theButton = (NSButton *)sender;

然后我将 theButton.enabled = NO; 替换为 [theButton setEnabled = NO];

这是我完成的代码:

- (IBAction)hit:(id)sender {
    Application *app = [[Application alloc] init];
    NSButton *theButton = (NSButton *)sender;
    int nc = [app dealCard];
    [userOne setIntValue:tu];
    [userTwo setIntValue:nc];
    tu += nc;
    [totalUser setIntValue:tu];
    BOOL bust = [app checkBust:tu];
    if (bust == YES) {
        [console setIntValue:1];
        [theButton setEnabled = NO];
    }
}

I found the problem. It turns out I was using an NSButton instead of a UIButton so I changed the declaration to: NSButton *theButton = (NSButton *)sender;.

Then I replaced theButton.enabled = NO; to [theButton setEnabled = NO];.

So here's my finished code:

- (IBAction)hit:(id)sender {
    Application *app = [[Application alloc] init];
    NSButton *theButton = (NSButton *)sender;
    int nc = [app dealCard];
    [userOne setIntValue:tu];
    [userTwo setIntValue:nc];
    tu += nc;
    [totalUser setIntValue:tu];
    BOOL bust = [app checkBust:tu];
    if (bust == YES) {
        [console setIntValue:1];
        [theButton setEnabled = NO];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文