在减少模式下以秒为单位显示时间.在表格视图中:iphone [英] show time in seconds in decrease mode. In table view: iphone

查看:37
本文介绍了在减少模式下以秒为单位显示时间.在表格视图中:iphone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个5行的表格视图.第一行显示一个减少的数字,以秒为单位表示时间,即30、29、28 ...0.这是为了让用户在30秒内从表视图中选择一个动作.如何实现?

I have a table view with 5 rows. The first row shows a decreasing digit indicating the time in seconds, i.e 30, 29, 28 ... 0. This is for the user to choose an action from the table view within 30 seconds. How is this implemented?

推荐答案

设置重复NSTimer ,它每秒触发一次,并在30秒后失效.每次触发时,都应更新相关的表格单元格.因为NSTimers可能不会按预期的时间触发(在某些情况下可能会大大延迟),所以我不建议使用其触发来跟踪经过了多少时间.而是在倒计时开始时记下未来30秒的时间.然后,您的单元格应显示该时间减去当前时间.当NSTimer触发时,通过再次计算结束时间减去当前时间来更新单元格.当该值变为零时,使计时器无效.

Set up a repeating NSTimer that fires once a second and invalidates after thirty seconds. Each time it fires, it should update the relevant table cell. Because NSTimers may not fire quite when their supposed to (and in some cases can be significantly delayed), I don't recommend using its firing to keep track of how much time has passed. Instead, at the beginning of the countdown, note the time that will be 30 seconds in the future. Your cell should then display that time minus the current time. When the NSTimer fires, update the cell by again calculating your end time minus the current time. When the value gets to zero, invalidate the timer.

这篇关于在减少模式下以秒为单位显示时间.在表格视图中:iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆