다음 코드를 컴파일했지만 명백한 런타임 오류가 없습니다. 그러나, 나는 그것을 실행할 때 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];
}
초만 추적하고 텍스트 필드의 값을 모델 데이터로 사용하는 대신 형식을 지정하는 제안에 동의합니다. – Wevah
제안에 큰 감사드립니다. 나는 왜 내가 그러한 멍청이 행동을했는지 모른다. 나는 그것을 수정하고 수정 된 버전을 게시 할 것입니다. 도움을 감사하십시오. – dman
@deesho : 천만에요. 행운을 빕니다! –