NSTime创建一个timeInterval
在我的应用程序中,我在方法
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应该是什么,并且也不在彼此的一秒之内。
没有找到相关结果
已邀请:
1 个回复
敦肌
是浮点类型,所以你需要 使用适当的占位符
而不是
或 在调用
时将
转换为int。 我认为 - 贾斯汀所说的是什么。 在旁边 考虑一下你在那里做什么: 不应该是“时间流逝”吗?