1
timer1Elapsed가 카운트 다운 타이머를 마친 후 다음 timer2Elapsed로 이동하고, 카운트 다운을 마친 후 timer1Elapsed로 이동하여 카운트 다운을 반복하는 등의 작업을 5 회 반복하는 방법. 조건 A와 B에 고정 시간이 있다고 (A → B → A → B ... 5 번) 나타나는 것처럼 보입니다. A는 1 분, B는 30 초입니다. 내가 초보자이기 때문에 오타를하지 말아주세요. 코드가 잘못되어 있으면 수정하십시오. 관대하십시오.NSTimer 내 코드를 수정하는 방법
- (void) timer2Elapsed:(id)timer
{
...
if (remainingTime <= 0)
{
[timer invalidate];
[NSTimer scheduledTimerWithTimeInterval:0.99 target:self selector:@selector(timer3Elapsed:) userInfo:nil repeats:YES];
}
myDisplay.text = [NSString stringWithFormat:@"%d : %d : %d", hour , minute, second];
}
- (void) timer1Elapsed:(id)timer
{
...
if (remainingTime <= 0)
{
[timer invalidate];
[NSTimer scheduledTimerWithTimeInterval:0.99 target:self selector:@selector(timer2Elapsed:) userInfo:nil repeats:YES];
}
myDisplay.text = [NSString stringWithFormat:@"%d : %d : %d", hour , minute, second];
}
이 당신이 다른 전화를 하나 개의 타이머가 필요하면 내 버튼
- (IBAction)startBtn:(id)sender {
[NSTimer scheduledTimerWithTimeInterval:0.99 target:self selector:@selector(timer1Elapsed:) userInfo:nil repeats:YES];
}
를 사용할 수 있습니까? 5 번 반복해서 말하는거야? – Piyo
타이머가 호출 될 때마다 증가하는 카운터 변수를 클래스에 추가합니다. 타이머가 5에 도달하면 새 타이머를 스케 칭하지 않습니다. –
@Piyo는 업데이트 된 응답을 확인하고 정적 정수를 사용하여 5 회로 제한하는 방법을 보여줍니다. –