【发布时间】:2016-09-15 02:02:57
【问题描述】:
我已经尝试了 2 天,搜索高低,无法让毫秒工作。小时、分钟和秒可以正常工作,但毫秒不会。
我制作了一个 lapCounter,它可以向上计数并且毫秒数没有问题。
这是 lapCounter 的工作代码,它计数 UP 和毫秒工作:
int hours = (UInt8)(elapsedTime /(60*60));
int mins = (UInt8)(elapsedTime / 60.0);
elapsedTime -= (mins * 60);
int secs = (UInt8)(elapsedTime);
elapsedTime -= (secs);
int mms = (UInt8)(elapsedTime * 100);
但我无法让 TimePicker Count DOWN,工作。
这就是我为 TimePicker Count DOWN 准备的内容:
int afterRemainder;
int remainder;
NSTimeInterval countDownTime;
NSTimer *countDownTimer;
bool startCountDown;
- (IBAction)startCountDownButton:(id)sender {
if (startCountDown == false) {
countDownTime = (NSTimeInterval)_datePicker.countDownDuration;
remainder = countDownTime;
afterRemainder = countDownTime - remainder%60;
countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateCountDown) userInfo:nil repeats:YES];
startCountDown = true;
}
-(void)updateCountDown {
afterRemainder --;
int hours = (int)(afterRemainder / (60 * 60));
int mins = (int)(afterRemainder / 60) - (60 * hours);
int secs = (int)(afterRemainder - (60 * mins) - (60 * hours * 60));
int mms = (int)(afterRemainder - (3600 * secs) - (mins * 60));
self.displayCountDown.text = [[NSString alloc] initWithFormat:@"%02d", hours];
self.displayCountDownMins.text = [[NSString alloc] initWithFormat:@": %02d", mins];
self.displayCountDownSecs.text = [[NSString alloc] initWithFormat:@"%02d", secs];
self.displayCountDownMMs.text = [[NSString alloc] initWithFormat:@":%2d", mms];
}
【问题讨论】:
-
定义“不起作用”。究竟是什么问题?在你的问题中给出明确的例子(不是在 cmets 中)。
-
@rmaddy 嗨,感谢您的发帖。毫秒不以毫秒为单位倒计时。出现了一些疯狂的数字,我已经尝试了所有方法。
-
@rmaddy 失败的毫秒数。
-
为什么你的小时、分钟、秒和毫米的上下计算有如此大的不同?它们应该是相同的。
-
我试过了。这就是我不明白的。但是小时、秒和分钟都可以正常工作。
标签: ios objective-c countdown timepicker milliseconds