0

Okay i know this has been a question asked b4, but since it should be easy to answer i would like to get a better answer. I have a start and a stop button on a timer. I want the play button to be disabled while the clock is running and enabled when the clock is stopped, visa versa, but also i would like it to be hidden when its disabled, so could some show me the code to disable and hide a button that has been recently pressed and then reenabled and visible when the other one is pressed.

4

2 に答える 2

2

ボタンに IBOutlets を設定し、直接アクセスする必要があります。Xcodeでそれらをリンクすることを忘れないでください

@property (strong, nonatomic) IBOutlet UIButton *startButton;
@property (strong, nonatomic) IBOutlet UIButton *stopButton;

再生ボタンのタップにリンクされたアクション:

[self->stopButton setEnabled:YES];
[self->stopButton setHidden:NO];

[self->startButton setHidden:YES];
[self->startButton setEnabled:NO];

次に、停止ボタンをタップすると:

[self->stopButton setEnabled:NO];
[self->stopButton setHidden:YES];

[self->startButton setHidden:NO];
[self->startButton setEnabled:YES];
于 2012-07-12T16:06:09.947 に答える
0

XIB では、ボタンを作成して ViewController.h に接続する必要があります。

interfaceあなたが持っている必要があります

IBOutlet UIButton *btn1;
IBOutlet UIButton *btn2;

-(IBAction)b1:(id)sender;
-(IBAction)b2:(id)sender;

implementation次のように書く必要があります。

viewDidLoad

btn1.enabled = no;


-(IBAction)b1 {
    btn1.enabled = no;
    btn1.hidden = yes;

    btn2.enabled = yes;
    btn2.hidden = no;
}

 -(IBAction)b2 {
    btn2.enabled = no;
    btn2.hidden = yes;

    btn1.enabled = yes;
    btn1.hidden = no;
} 

hidden = yes十分だと思います

于 2012-07-12T16:08:52.537 に答える