我有以下方法来更新显示简单时间的标签
-(void)updateTimeLabel:(NSTimer *)timer{
NSInteger secondsSinceStart = (NSInteger)[[NSDate date] timeIntervalSinceDate:_startTime];
NSInteger seconds = secondsSinceStart % 60;
NSInteger minutes = (secondsSinceStart / 60) % 60;
NSInteger hours = secondsSinceStart / (60 * 60);
NSString *result = nil;
if (hours > 0) {
result = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
}
else {
result = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];
}
_totalTime = result;
_totalTimeLabel.text = result;
}
然后我将其称为按钮的操作:
-(IBAction) startTimer{
_startTime = [NSDate date];
_walkRouteTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTimeLabel:) userInfo:nil repeats:YES];
[_walkRouteTimer fire];
}
但是当我运行应用程序时,我遇到了一个错误的访问错误并且应用程序崩溃了,谁能帮我解决这个问题?
提前致谢