기본적으로 원하는 것은 1 초마다 발생하는 이벤트 또는 1/10 초 간격으로 발생하는 이벤트입니다. 그러면 타이머가 작동 할 때 UI가 업데이트됩니다.
다음은 타이머를 생성하고 실행 루프에 추가합니다. 필요할 때 타이머를 죽일 수 있도록 어딘가에 타이머를 저장하십시오.
- (NSTimer*)createTimer {
// create timer on run loop
return [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerTicked:) userInfo:nil repeats:YES];
}
이제 타이머 틱에 대한 처리기를 작성 : 사용자가 버튼을 명중
- (void)timerTicked:(NSTimer*)timer {
// decrement timer 1 … this is your UI, tick down and redraw
[myStopwatch tickDown];
[myStopwatch.view setNeedsDisplay];
// increment timer 2 … bump time and redraw in UI
…
}
경우 카운트를 재설정하거나 시작하거나 똑딱을 중지 할 수 있습니다. 타이머를 끝내려면 다음과 같이 무효 메시지를 보내주십시오.
- (void)actionStop:(id)sender {
// stop the timer
[myTimer invalidate];
}
희망이 있으면 도움이됩니다.
참조 http://stackoverflow.com/questions/3519562/how-do-i-write-a-timer-in-objective-c –