user1304216
user1304216

Reputation: 5

NSTimer only counting down seconds?

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

Upvotes: 0

Views: 190

Answers (2)

user1354889
user1354889

Reputation:

If the input is the countDownInt (in minutes), then

int countDownIntSeconds = countDownInt;

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

Upvotes: 0

JRaymond
JRaymond

Reputation: 11782

If you want user input to be in minutes, you should probably multiply it by 60 before you start decrementing seconds.

Upvotes: 1

Related Questions