我有和NSTimer在尝试将其格式化为MM:SS时,计数器计数到一秒然后停止。这只会在我将秒数除以60时发生。我似乎无法理解为什么。有什么建议吗?
- (void)showActivity{
int currentTime = [time.text intValue];
int newTime = currentTime + 1;
int seconds = newTime % 60;
//int minutes = newTime / 60;
time.text = [NSString stringWithFormat:@"%i", seconds];
}
- (void)delayedMethod {
//Delay this action
[locationManager startUpdatingLocation];
timeTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
}
答案 0 :(得分:0)
%d格式字符串用于十进制值,并且您想要使用整数。这通常会导致奇怪。尝试使用:
time.text = [NSString stringWithFormat:@"%i:%i", minutes, seconds];