views:

49

answers:

2

I have an IBAction button that I would like to enable after a 30 second delay. the button would be in the view but disabled for 30 secs.

does anyone know how I would go about doing this?

here's what I have - a simple IBAction that plays some audio:

-(IBAction) playSound:(id)sender {

    [theAudio play];

}

thanks for any help.

+1  A: 

In viewDidLoad or other suitable method that you want:

[myButton setUserInteractionEnabled:FALSE];
[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(enableButton:) userInfo:nil repeats:NO];

Then,

- (void)enableButton:(NSTimer *)timer {
    [myButton setUserInteractionEnabled:TRUE];
}

NOTE : I have not compiled the code, just wrote. There might be typo.

taskinoor
thanks for your post
hanumanDev
+3  A: 

You can use this:

- (IBAction)playSound:(id)sender
{
    [theAudio play];
    UIButton *theButton = (UIButton *) sender;
    theButton.enabled = NO;
    [self performSelector:@selector(enableButton:) withObject:theButton afterDelay:30.0];
}

- (void)enableButton:(UIButton *)button
{
    button.enabled = YES;
}

Assuming that you want to disable the button when it gets pressed.

Rits
that's great. thanks!
hanumanDev