Note that there are some explanatory texts on larger screens.

plurals
  1. PONSTimer stops the first time I tell it to, then refuses to stop
    primarykey
    data
    text
    <p>I have declared an <code>NSTimer</code> in my <code>UIViewController</code> header as such:</p> <pre><code>NSTimer *mainTimer; </code></pre> <p>And I start it up in the <code>viewWillAppear</code> method in the implementation, so:</p> <pre><code>mainTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateAll) userInfo:nil repeats:YES]; </code></pre> <p>I have a button that flips the view over (standard utility app template) called <code>showInfo</code> and it has the command:</p> <pre><code>[mainTimer invalidate]; </code></pre> <p>When my app launches, the timer starts and does it's thing. The first time I tap that button and the view flips, the timer stops. When I'm done with the <code>flipSideViewController</code> and the main view reappears, the timer starts again. So far, good. The problem is that subsequent button presses (and thus calls to <code>[mainTimer invalidate]</code> don't make the timer stop. It just keeps going. I can flip back and forth all I want and it continues to update. For grins, I put two <code>invalidate</code> calls in a row, but that crashes.</p> <p>UPDATE:</p> <p>Found the problem. Upon returning from the <code>flipSideViewController</code>, I was calling <code>viewWillAppear</code> myself, which would create the timer. The run loop also calls <code>viewWillAppear</code> automatically, so a second timer was created. This only happened after I had visited the flip side once so the timer (single instance) would stop normally when I flipped the first time. Odd that I can create two timers with the same name though...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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