Objective c iOS:为什么计时器(和performSelector)会立即触发所选方法?

Objective c iOS:为什么计时器(和performSelector)会立即触发所选方法?,objective-c,ios,Objective C,Ios,我尝试使用这两种方法: [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(enableGestures) userInfo:nil

我尝试使用这两种方法:

[NSTimer scheduledTimerWithTimeInterval:2.0
                                     target:self
                                   selector:@selector(enableGestures)
                                   userInfo:nil
                                    repeats:NO];

要触发EnablePictures方法,但在两个版本中都会触发两次!(计时器启动时为第一个,2秒后为第二个)。第二个片段也是如此。为什么?


感谢scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:消息的选择器应具有以下签名:

- (void)enableGestures:(NSTimer*)theTimer
我编写了一个小测试代码,如果没有选择器的正确签名,有时会立即调用选择器,然后在计时器完成时再次调用。当我将其更改为正确的签名时,选择器首先在适当的延迟后被调用。我从来没有在正确格式的签名中看到过这个问题,大约有一半的时间在不正确的签名中看到过这个问题

我试过第二个版本,每次都能正常工作


如果这两种版本的计时代码都是一致的,则代码中的其他地方会发送
启用手势
消息。

这毫无意义。
performSelector…afterDelay
无法立即触发。您可能需要显示一些周围的代码。您在
启用手势
中做什么?
- (void)enableGestures:(NSTimer*)theTimer