NSTimer for UITableviewcell similar to World Clock app

久未见 提交于 2019-12-07 06:40:18

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3805668/nstimer-for-uitableviewcell-similar-to-world-clock-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!