我编译了以下代码,没有明显的运行时错误;但是,当我运行它时,显示会在 00:00:01 冻结。如果我只显示秒属性,它就可以工作。有没有人看到我在这段代码中遗漏的明显疏忽?我知道开始按钮可能存在内存泄漏,但我最终会解决这个问题。
提前致谢。
#import "StopwatchViewController.h"
@implementation StopwatchViewController
- (IBAction)start{
//creates and fires timer every second
myTimer = [[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showTime) userInfo:nil repeats:YES]retain];
}
- (IBAction)stop{
[myTimer invalidate];
myTimer = nil;
}
- (IBAction)reset{
[myTimer invalidate];
time.text = @"00:00:00";
}
(void)showTime{
int currentTime = [time.text intValue];
int new = currentTime +1;
int secs = new;
int mins = (secs/60) % 60;
int hours = (mins/60);
time.text = [NSString stringWithFormat:@"%.2d:%.2d:%.2d",hours, mins, secs];
}