2011-02-04 59 views
1

我需要一点帮助,我有一个方法; countDown在iTunes发送通知时被调用,然后countDown方法运行方法timerHit,该方法获取双精度值,然后将该值设置为标签,将方法countDown设置为重复运行timerHit,但它看起来不像正在工作。Objective-C帮助NSTimer不重复

这是我到目前为止,任何帮助将不胜感激。

- (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]; 
    } 
} 

谢谢,萨米。

+0

从我已经意识到它减去从价值,但随后没有按”码打转转重复并更新标签。 – Sami 2011-02-04 12:54:51

回答

2

如果计时器上一个线程,那么你应该在一个活跃的运行循环,像这样运行:

NSRunLoop *mLoop = [NSRunLoop currentRunLoop]; 

[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerHit:) userInfo:nil repeats:YES]; 

mRunLoop = YES; 
while (mRunLoop && [mLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.01]]);