我一直在嘗試2天,搜索高和低,無法獲得毫秒的工作。小時,分鐘&秒工作正常,但毫秒不會。TimePicker以毫秒爲單位倒計時
我已經做了一個lapCounter,它向上計數並且毫秒沒有問題。
下面是lapCounter,其計數的工作代碼和毫秒工作:
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倒計時,工作。
這就是我對TimePicker倒計時:
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];
}
定義 「不工作」。究竟是什麼問題?在你的問題中給出清晰的例子(不在評論中)。 – rmaddy
@rmaddy嗨感謝張貼。毫秒不會以毫秒爲單位倒數。一些瘋狂的數字出現了,我嘗試了一切。 –
@rmaddy這是數毫秒失敗的數學。 –