0

I am using an NSTimer that runs down from 15 seconds in a multiple choice quiz app. The app has two possible outcomes. The time may run down to zero, and the incorrectAnswer view is shown, in which case the Timer is invalidated/stopped and the static integer for its time is reset back to 15 for the next question.

However, the other possible outcome is that an answer is selected before time runs down, in which case I use the method viewWillDisappear to trigger further action. My problem is that I cannot reset the static integer for time from this method, because it is declared in the method above. I tried declaring it in the .h file, but there are problems because the integer is static.

I want to know if there is a boolean expression that evaluates if the current view has disappeared, because this way I can keep everything in the same method and be able to reset the static integer for time.

jrturton
  • 118,105
  • 32
  • 252
  • 268
Abiel G
  • 3
  • 3
  • if you are using viewcontrollers, you should find answers to the question below useful http://stackoverflow.com/questions/2777438/how-to-tell-if-uiviewcontrollers-view-is-visible – tzl Sep 15 '12 at 19:08
  • Some of your code would be helpful. It sounds like you're a beginner at ios, so you may be using terms like "static" with a different meaning - it would be easier to help with your code if we knew what you already had. – jrturton Sep 16 '12 at 06:16

1 Answers1

0

First, if your timer variable local to the class, it doesn't have to be declared as static. Secondly, you have two opportunities to address your problem from the viewController: viewWillDisappear and viewDidDisappear. Lastly, if you need to know if a view property has changed, you can do it via a KVO method. The problem you'll run into is if the view has truly disappeared, the view object may be toast by the time you reference it. Without more info, there is no way to tell what problem you're truly having.

Also, once you invalidate a timer, you can no longer use it. You must create a new timer.

rsswtmr
  • 1,776
  • 5
  • 16
  • 26