禁用 IBAction 链接按钮
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UIButton
是UIResponder
的子类,它具有enabled
属性。将其设置为NO
以禁用按钮的操作。例如UIButton
is a subclass ofUIResponder
which has anenabled
property. Set this toNO
to disable the action from the button. E.g.我发现了问题。事实证明,我使用的是
NSButton
而不是UIButton
,因此我将声明更改为:NSButton *theButton = (NSButton *)sender;
。然后我将
theButton.enabled = NO;
替换为[theButton setEnabled = NO];
。这是我完成的代码:
I found the problem. It turns out I was using an
NSButton
instead of aUIButton
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: