Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to stop an NSTimer that I don't know is released or not
    text
    copied!<p>Sorry to ask this question, but it's now day 3 I try to solve this problem and have no progress so far.</p> <p>The problem is this: during a game there is a pause between the user answered a question and the next question. Also in several other cases there are such pauses in gameplay. For this I use one NSTimer.</p> <p>In .h I have:</p> <pre><code>@property(nonatomic,retain) NSTimer *scheduleTimer; </code></pre> <p>and in the .m</p> <pre><code>@synthesize scheduleTimer; scheduleTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target: self selector: @selector(playFeedbackSound) userInfo: nil repeats: NO]; </code></pre> <p>now this works just fine. But when the user exits the ViewController I need to invalidate the timer. Otherwise the timer will fire and then crash the app or pops up stuff that does not belong in the other view etc.</p> <p>Therefore I write:</p> <pre><code>- (void)viewWillDisappear:(BOOL)animated { [scheduleTimer invalidate]; } </code></pre> <p>now this does the job if the timer is actually set. But if there is no such timer scheduled, the app just crashes. </p> <p>I tried probably everything there is, including @try (which crashes the app too, Zombie says "<em>*</em> -[CFRunLoopTimer invalidate]: message sent to deallocated instance 0x567640"). Since the timer gets released after it is done, a [scheduleTimer isValid] will just crash the app as well.</p> <p>Now I'm already pretty desperate, and as a last resort I'm thinking of replacing the timer with UIView animateWithDuration that does nothing visible.</p> <p>However, I think this should be a pretty standard situation. I just don't know why I can't find an answer to this very obvious task. Can you help? Thank you</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload