Estoy usando NSTimer anidado en una aplicación. Tengo dos problemas aquí.cómo deshabilitar NSTimer en objetivo-c
- Cómo volver a iniciar el contador de tiempo en esta función
- (void)updateLeftTime:(NSTimer *)theTimer
- Cómo matar temporizador anterior debido
- (void)updateLevel:(NSTimer *)theTimer
también está llamando por temporizador.
- (void)viewDidLoad {
[super viewDidLoad];
tmLevel=[NSTimer scheduledTimerWithTimeInterval:20.0f target:self selector:@selector(updateLevel:) userInfo:nil repeats:YES];
tmLeftTime=[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateLeftTime:) userInfo:nil repeats:YES];
}
- (void)updateLevel:(NSTimer *)theTimer {
static int count = 1;
count += 1;
lblLevel.text = [NSString stringWithFormat:@"%d", count];
tfLeftTime.text=[NSString stringWithFormat:@"%d",ANSWER_TIME];
tmLeftTime=[[NSTimer alloc] init];
tmLeftTime=[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateLeftTime:) userInfo:nil repeats:YES];
[self playMusic];
}
- (void)updateLeftTime:(NSTimer *)theTimer {
static int timeCounter=1;
timeCounter+=1;
tfLeftTime.text=[NSString stringWithFormat:@"%d", (ANSWER_TIME-timeCounter)];
}
el uso del método de invalidación – Narayana