У меня есть два NSTimers в моем приложении для iPhone. DecreaseTimer работает нормально, но TimerCountSeconds дает сбой, когда я вызываю [timerCountSeconds isValid] или [timerCountSeconds 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];
}
}
Что я сделал не так? Не могли бы вы мне помочь?
DecreaseTimerдля переменных экземпляра, как правило, очень плохая идея. Имена, начинающиеся с заглавной буквы, используются для классов и структур. Рассмотрите возможность использования последовательного стиля, который поддерживает Apple. - person Stefan Arentz   schedule 11.09.2010