iPhone延迟后调用一个函数

时间:2010-09-01 00:13:41

标签: iphone

我有一些代码,我显示一个精灵N秒。 N秒后删除此框,我想调用我可以选择的功能。例如,在10秒钟内我想调用showBoxEnded。

我在这里看到,看到我可以使用SEL功能。我写道:

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

我可以调用callFunc来设置将被调用的函数:

-(void) callFunc:(SEL)func;

但是,当我尝试这个时,我的函数永远不会被调用。我在这里错过了什么吗?这有可能像在C ++中一样吗?

是否可以将SEL函数作为参数传递给函数?

谢谢!

2 个答案:

答案 0 :(得分:7)

您正在寻找[self performSelector:@selector(myfunc) withObject: afterDelay:];

答案 1 :(得分:2)

您可以使用计时器并在提到的延迟后调用函数:

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