NSTimer - 二进制操作数无效%错误
我正在尝试用音轨上剩余的时间(以分钟和秒为单位)更新 UILabel。我收到 Invalid operand to binary % 错误。代码如下:
- (void)updateTimeLeft
{
NSTimeInterval timeLeft = self.player.duration - self.player.currentTime;
int min = timeLeft / 60;
int sec = timeLeft % 60;
self.timeDisplay.text = [NSString stringWithFormat:@"%d : %d", min,sec];
}
我将代码更改为以下内容:
int sec = lroundf(timeLeft) % 60;
错误消失了,但我怀疑这里有问题,因为计时器从 5:00 正确倒计时到 4:10,但随后显示 4:9 而不是 4: 09
感谢您的帮助
I'm trying to update a UILabel with the amount of time left on an audio track in minutes and seconds. I'm getting an Invalid operand to binary % error . Here's the code:
- (void)updateTimeLeft
{
NSTimeInterval timeLeft = self.player.duration - self.player.currentTime;
int min = timeLeft / 60;
int sec = timeLeft % 60;
self.timeDisplay.text = [NSString stringWithFormat:@"%d : %d", min,sec];
}
I changed the code to the following:
int sec = lroundf(timeLeft) % 60;
The error goes away, but I suspect that there's a problem here because the timer counts down correctly from 5:00 to 4:10, but then displays 4:9 instead of 4:09
thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
修改如下,
Alterations below,