次のコードをコンパイルしましたが、明らかな実行時エラーはありません。ただし、実行すると、表示が 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];
}