メソッドのアプリケーションに次のコードがありますupdateLabel2
。
timeLeft = [[NSDate date] timeIntervalSinceDate:[[NSUserDefaults standardUserDefaults] objectForKey:@"lastDate"]];
[[self timer] setText:[NSString stringWithFormat:@"Time Remaining: %f", timeLeft]]; //Set the label text
timer はラベルであることに注意してください。
以前は、次のコードが実行されます。
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"lastDate"];
self.repeatTimer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updateLabel2)
userInfo:nil
repeats:YES];
私の問題は、timeLeft がランダムな整数に設定されていることです。これは、timeIntervals がどうあるべきか明確ではなく、互いに 1 秒以内ではないことです。