NSTimer 倒计时,带标签显示剩余时间
我的应用程序需要帮助。我不知道如何在我的应用程序中使用 NSTimer,也不知道如何使剩余时间值显示在标签上。另外,是否可以获取进程列表并使用单选按钮来选择计时器到时后是否隐藏或终止进程?
I need help for my app. I dont know how to use a NSTimer
in my app, and also don't know how to make the value of time left display on a label. Also, is it possible to get a list of processes and use radio buttons to select whether to hide or kill a process after the timer is up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,这可能是一本很好的读物:使用计时器
最后,这个答案应该完全符合您的要求。再多搜索一下,您就会发现这个问题。
First of all, this might be a good read: Using Timers
Finally, this answer should do exactly what you're asking for. With a little more searching you would have found this question.
NSTimer 将定期调用您的方法 - 您可以将其设置为 1 秒周期并在每次滴答时递减。或者,为了更可靠,您可以让它更频繁地运行并处理实际的 POSIX gettimeofday() 来自己跟踪时间并计算出剩余时间
,是的,这些事情都是可能的。对于单选按钮,您只需获取它们的状态并根据需要采取行动即可。您可以将它们设置为在它们发生变化时通知您,或者当您执行指定的行为时您可以检查它们的状态。
An NSTimer is going to call your method at a regular interval - you can set this up to a 1 second period and decrement each tick. Or, to be more reliable, you can have it run more frequently and handle actual POSIX gettimeofday() to track time yourself and figure out the time remaining
And yes those things are possible. For radio buttons you would simply get their state and act upon that however you like. You can set them up to tell you when they change, or when you do your specified behavior you can check their status.