I would like to build a few simple countdown timers in a UITableview. I noticed the World Clock app has animated clocks in each of it's rows. What is the best method to firing an NSTimer to update each table row? Can a single timer be run that updates all cells or should I have a custom view subclass with built in timer that is added to each row?
I am just trying to get a proper course of action.
One timer is sufficient. When it fires, ask the table view for the visible cells and update them one by one. You could also just call reloadData
when the timer fires but depending on how you draw your cells you might do more work than necessary and you cannot use animations.
Just know that you need to schedule the timer to fire more than once a second. NSTimer isn't a precision device--you're scheduling it for the next available processor slot after the time duration you specify. So a 1 second NSTimer WON'T fire in exactly a second, and can actually accumulate quite a lot of error over time. You want it to come alive several times a second, look at the current time, notice when a second has passed, and do the UI/data updates appropriate to that fact.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With