2011-02-04 28 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]]);