문제

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
    });
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top