我是客观C的新手。
我一直在玩倒计时已有一段时间了,我似乎无法让它发挥作用。
我在故事板中连接的东西和按钮反应,但它似乎只是随机倒计时。
为什么我不倒数到10点到09:59。
- (void)showActivity{
int currentTime = [time.text intValue];
int newTime = currentTime - 1;
int seconds = newTime % 60;
int minutes = (newTime / 60) % 60;
time.text = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];
}
答案 0 :(得分:0)
如果time.text
为“10:00”,则调用[time.text intValue]
只会返回整数10
。
我建议创建一个单独的变量(可能是NSTimeInterval
)来跟踪剩余的秒数,然后让time
文本标签负责显示为分钟:秒
e.g。
@property NSTimeInterval time;
@property UILabel *timeLabel; // "time" in your original code
- (void)showActivity {
NSTimeInterval newTime = self.time - 1;
int minutes = floor(newTime / 60);
int seconds = round(newTime - (minutes * 60));
self.timeLabel.text = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];
self.time = newTime;
}