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应该是什么,并且也不在彼此的一秒之内。     
已邀请:
你的格式字符串是错误的: 因为
NSTimeInterval
是浮点类型,所以你需要 使用适当的占位符
%f
而不是
%d
或 在调用
-[NSString stringWithFormat:]
时将
timeLeft
转换为int。 我认为 - 贾斯汀所说的是什么。 在旁边 考虑一下你在那里做什么: 不应该是“时间流逝”吗?     

要回复问题请先登录注册