David Nelson
David Nelson

Reputation: 752

iPhone calling a function after a delay

I have some code where I display a sprite for N number of seconds. This box is removed after N seconds and I'd like to call a function that I can select. For example, in 10 seconds I want to call showBoxEnded.

I looked on here and saw I can use the SEL function. I wrote:

-(void)caller:(id)sender
{
    NSLog(@"Function Called!");
}

I can call callFunc in order to set the function that will be called:

-(void) callFunc:(SEL)func;

However, when I try this, my function is never called. Am I missing something here? Is this possible like it is in C++?

Is it possible to just pass the SEL function as a parameter to a function?

Thanks!

Upvotes: 2

Views: 4393

Answers (2)

Graham Perks
Graham Perks

Reputation: 23398

You're looking for [self performSelector:@selector(myfunc) withObject: afterDelay:];

Upvotes: 7

neha
neha

Reputation: 6377

You can use timer and call a function after mentioned delay as:

timer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(taskOnTimer) userInfo:nil repeats:NO];

Upvotes: 2

Related Questions