【发布时间】:2014-07-15 06:46:12
【问题描述】:
这是我的示例代码..我每秒钟都有一个计时器来触发函数“调用”。
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(call:) userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"sdfsf",@"wsdf", nil] repeats:YES];
-(void)call :(NSTimer *)timer{
NSLog(@"called outside %@",timer.userInfo);
static dispatch_once_t myDisPatch;
dispatch_once(&myDisPatch, ^{
NSLog(@"called inside");
});
}
我的疑问是,当我们将“static dispatch_once_t myDisPatch”更改为“dispatch_once_t myDisPatch”时。然后计时器自动失效。它不会再次调用该函数。为什么当我从 dispatch_once_t 中删除 static 关键字时会发生这种情况?为什么它会停止计时器?提前致谢。
【问题讨论】:
标签: objective-c ios7 grand-central-dispatch nstimer