我在方法的应用程序中有以下代码updateLabel2
:
timeLeft = [[NSDate date] timeIntervalSinceDate:[[NSUserDefaults standardUserDefaults] objectForKey:@"lastDate"]];
[[self timer] setText:[NSString stringWithFormat:@"Time Remaining: %f", timeLeft]]; //Set the label text
请注意,计时器是一个标签。
更早之前,执行以下代码:
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"lastDate"];
self.repeatTimer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updateLabel2)
userInfo:nil
repeats:YES];
我的问题是 timeLeft 被设置为随机整数,这绝对不是 timeIntervals 应该是的,并且彼此也不在一秒内。