I have a tabbar-based app with three tabs, one of them is a running clock. To animate the clock UI, I use an NSTimer that fires once a second. If the user will be switching in and out of the various tabs, how should I manage this timer?
- Can I just use
scheduledTimerWithTimeIntervalto create and schedule the timer when the app is first run and let it die when the app closes? Or should I maintain an instance variable for the timer in the rootview controller for the clock tab and useaddTimer:forMode:andinvalidate? - If the ladder, how often should I add and invalidate the timer? In my
viewWillAppearandviewWillDisappearmethods for the rootview controller of the clock tab? Somewhere else?
Thanks so much in advance for your wisdom!
I would do the following:
if your Clock-View appears -> set the Clock to the current time, then start a timer that updates the clock every second:
if the clock view is about to disappear invalidate the timer
This way you don’t do unnecessary updates.
hope I could help,
sam