You can use performSelector: withObject: afterDelay
[self performSelector:@selector(myFunc) withObject:nil afterDelay:10.0];
Place this in the IBAction call that is called when your button is pressed, myFunc
will be called 10 seconds later.
문제
I have an IBAction
linked to a button. When the button is clicked, a .wav file gets played.
How can I make the IBAction
run 10 seconds after the click of the button?
해결책
You can use performSelector: withObject: afterDelay
[self performSelector:@selector(myFunc) withObject:nil afterDelay:10.0];
Place this in the IBAction call that is called when your button is pressed, myFunc
will be called 10 seconds later.
다른 팁
You can use dispatch_after
to defer code execution:
- (IBAction) onAction: (id)sender
{
double delayInSeconds = 10.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// do delayed work here
});
}