Tengo dos NSTimers en mi aplicación de iPhone. DecreaseTimer funciona bien, pero TimerCountSeconds se bloquea cuando llamo a [timerCountSeconds isValid] o [timerCountSeconds invalida]. Se usan así:NSTimer falla, cuando llamo a [Timer isValid] o [Timer invalidate]
-(id)initialize { //Gets called, when the app launches and when a UIButton is pressed
if ([timerCountSeconds isValid]) {
[timerCountSeconds invalidate];
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //Gets called, when you begin touching the screen
//....
if ([decreaseTimer isValid]) {
[decreaseTimer invalidate];
}
timerCountSeconds = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(runTimer) userInfo:nil repeats:YES];
//....
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {//Gets called, when you stop touching the screen(not if you press the UIButton for -(id)initialize)
//...
decreaseTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(decrease) userInfo:nil repeats:YES];
//...
}
-(void)comept3 { //Gets calles when you rubbed the screen a bit
if ([timerCountSeconds isValid]) {
[timerCountSeconds invalidate];
}
}
¿Qué hice mal? ¿Puedes ayudarme?
has inicializado TimerCountSeconds y DecreaseTimer? – olliej
Los declare en el archivo de encabezado ... Los inicié en los métodos "touchesEnded" y "touchesBegan" – esanits
Mostrar más código. Además, tener nombres como 'DecreaseTimer' por ejemplo, variables es generalmente una muy mala idea. Los nombres que comienzan con una letra mayúscula se usan para clases y estructuras. Considere usar un estilo consistente que Apple defiende. –