Ho due NSTimers nella mia app per iPhone. DecreaseTimer funziona correttamente, ma TimerCountSeconds si arresta in modo anomalo quando chiamo [timerCountSeconds isValid] o [timerCountSeconds invalidate]. Sono usati così:NSTimer si arresta in modo anomalo, quando chiamo [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];
}
}
Cosa ho fatto di sbagliato? Puoi aiutarmi per favore?
hai inizializzato TimerCountSeconds e DecreaseTimer? – olliej
Li ho dichiarati nel file di intestazione ... li ho inizializzati nei metodi "touchesEnded" e "touchesBegan" – esanits
Mostra altro codice. Inoltre, avere nomi come "DecreaseTimer" per variabili di istanza è generalmente una pessima idea. I nomi che iniziano con una lettera maiuscola vengono utilizzati per le classi e le strutture. Prendi in considerazione l'utilizzo di uno stile coerente consigliato da Apple. –