Thursday 22 August 2013

Calculating seconds to millisecond NSTimer

Calculating seconds to millisecond NSTimer

Trying to work out where I have screwed up with trying to create a count
down timer which displays seconds and milliseconds. The idea is the timer
displays the count down time to an NSString which updates a UILable.
The code I currently have is
-(void)timerRun {
if (self.timerPageView.startCountdown) {
NSLog(@"%i",self.timerPageView.xtime);
self.timerPageView.sec = self.timerPageView.sec - 1;
seconds = (self.timerPageView.sec % 60) % 60 ;
milliseconds = (self.timerPageView.sec % 60) % 1000;
NSString *timerOutput = [NSString stringWithFormat:@"%i:%i", seconds,
milliseconds];
self.timerPageView.timerText.text = timerOutput;
if (self.timerPageView.resetTimer == YES) {
[self setTimer];
}
}
else {
}
}
-(void)setTimer{
if (self.timerPageView.xtime == 0) {
self.timerPageView.xtime = 60000;
}
self.timerPageView.sec = self.timerPageView.xtime;
self.timerPageView.countdownTimer = [NSTimer
scheduledTimerWithTimeInterval:0.01 target:self
selector:@selector(timerRun) userInfo:Nil repeats:YES];
self.timerPageView.resetTimer = NO;
}
Anyone got any ideas what I am doing wrong?

No comments:

Post a Comment