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

問題を見つけました。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];
    }
}
于 2011-07-15T16:47:31.740 に答える
1

UIButtonは、そのサブクラスにプロパティUIResponderがありenabledます。NOボタンからのアクションを無効にするには、これをに設定します。例えば

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