【发布时间】:2013-12-10 15:14:29
【问题描述】:
我有一个简单的应用程序,它(目前)除了创建一个计时器之外所做的事情不多:
_time = [[NSTimer alloc] initWithFireDate: _nextDate
interval: 0.0f
target: self
selector: @selector(trackTime)
userInfo: nil
repeats: NO];
[[NSRunLoop currentRunLoop] addTimer:_time forMode:NSRunLoopCommonModes];
在 trackTime 函数中,我检查了规定的触发日期 (_nextDate) 与实际触发日期之间的差异:
NSTimeInterval secondsBetween = [_nextDate timeIntervalSinceDate:[NSDate date]];
从结果来看,调用函数似乎晚了 2 到 4 秒。
这正常吗?我需要不同的运行循环模式吗?我还能做些什么来获得更好的时机吗?
【问题讨论】:
标签: objective-c cocoa nsdate nstimer nsrunloop