0

My NSTimer is working but only counting down seconds? The minutes show up as "00" and the seconds count down, minutes stay at zero. The int countdownInt comes from user input and I have been testing by entering "45" for a 45 minute count down timer. The only thing that happens is that the seconds are counting down from "45"? countdownInt, seconds and minutes have all been declared int in the .h file

Thanks for your help!

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

2 回答 2

1

如果您希望用户输入以分钟为单位,您可能应该在开始递减秒数之前将其乘以 60。

于 2012-04-27T17:21:56.977 回答
0

如果输入是 countDownInt(以分钟为单位),则

int countDownIntSeconds = countDownInt;

countDownIntSeconds -= 1;
seconds = countDownIntSeconds;
minutes = countDownIntSeconds % 60;
countdownTimerLabel.text = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];
于 2012-04-27T17:24:47.747 回答