开发者

Disable an IBAction-linked button

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)开发者_如何学JAVAhit:(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?


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;


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];
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜