开发者

NSTimer - Invalid operand to binary % error

开发者 https://www.devze.com 2023-03-08 01:27 出处:网络
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:

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


Alterations below,

self.timeDisplay.text = [NSString stringWithFormat:@"%02d:%02d", min,sec];
0

精彩评论

暂无评论...
验证码 换一张
取 消