Objective-C 帮助 NSTimer 不重复
我需要一点帮助,我有一个方法; countDown 是在 iTunes 发送通知时调用的,然后 countDown 方法运行timerHit 方法,该方法获取双减一,然后将值设置为标签,countDown 方法被设置为重复运行timerHit,但似乎没有正在工作。
这是我到目前为止所拥有的,任何帮助将不胜感激。
- (void)countDown {
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerHit:) userInfo:nil repeats:YES];
}
- (void)timerHit:(NSTimer *)p_timer {
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
if ([iTunes isRunning]) {
double trackDuration = [[iTunes currentTrack] duration];
trackDuration--;
[duration setDoubleValue:trackDuration];
}
}
谢谢,萨米。
i need a little help i have a method; countDown which is called when iTunes sends a notification, the method countDown then runs the method timerHit which gets a double minuses one from it then sets the value to a label, the method countDown is set to repeatedly run timerHit, however it doesn't seem to be working.
Here's what i have so far, any help would be much appreciated.
- (void)countDown {
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerHit:) userInfo:nil repeats:YES];
}
- (void)timerHit:(NSTimer *)p_timer {
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
if ([iTunes isRunning]) {
double trackDuration = [[iTunes currentTrack] duration];
trackDuration--;
[duration setDoubleValue:trackDuration];
}
}
Thanks, Sami.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果计时器位于线程上,那么您应该在活动运行循环上运行它,如下所示:
If the timer is on a thread then you should run it on a active run loop like so: