2012-04-27 43 views
0

我的NSTimer正在工作,但只是倒計時秒?分鐘顯示爲「00」,秒數倒數,分鐘保持爲零。 int countdownInt來自用戶輸入,我一直在測試45分鐘倒計時器輸入「45」。唯一發生的事情是秒數從「45」開始倒數? countdownInt,秒和分鐘都在.h文件中聲明爲intNSTimer只能倒數秒?

感謝您的幫助!

countdownInt -=1; 
seconds = countdownInt % 60; 
minutes = (countdownInt/60) % 60; 
countdownTimerLabel.text = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds]; 

回答

1

如果你想用戶輸入要在幾分鐘內,你應該通過60開始遞減秒鐘,然後乘以。

+0

謝謝!這就是答案! – user1304216 2012-04-27 18:27:18

0

如果輸入的是countDownInt(以分鐘爲單位),然後

int countDownIntSeconds = countDownInt; 

countDownIntSeconds -= 1; 
seconds = countDownIntSeconds; 
minutes = countDownIntSeconds % 60; 
countdownTimerLabel.text = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];