1

我使用 Interface Builder 制作了一个按钮并将其链接到一个动作。我想禁用下面语句中的点击按钮。if

- (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.
    }
}

我应该怎么办?

4

2 回答 2

1

我发现了问题。事实证明我使用的是 anNSButton而不是 aUIButton所以我将声明更改为: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];
    }
}
于 2011-07-15T16:47:31.740 回答
1

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

UIButton *theButton = (UIButton *)sender;
theButton.enabled = NO;
于 2011-07-14T21:45:49.060 回答