What is the recommended approach for starting a countdown NSTimer
on one view and having it be accessible to stop interactively or to have run out in another?
I know one option is to have the NSTimer
never turn off once kicked off and just use a global variable to determine whether to countdown or not but that seems inefficient.
More details of what I'm trying do:
In the main view I have a label that will update with the count down 00:00:00 and a button that I want to open a countdown UIDatePicker
.
The second view with the UIDatePicker
also has a start and stop button that will kick off or stop the countdown.
This view will close and the label on the original screen will display the countdown based on what the user selected previously.
It seems the timer you needed is independent from any of the views. You can use a singleton instance which will init once then be accessed anywhere. It's kind of like a global variable you mention above but if you have more than two views that need access to the timer singleton might be the most suitable choose