一旦iOS中的系统日期更改,如何更改带有日期的标签? [英] How can I change a label with a date once the system date changes in iOS?
问题描述
我有一个简单的查询,但不知道该怎么做.
I have a simple query but don't know how to do it.
这就是我想要实现的目标:1)我有一个带有今天日期的 UILabel,即29/04/12"2) 在午夜,我希望该标签自动更新为30/04/12",而无需更改视图或按下任何按钮.
This is what I am trying to achieve: 1) I have a UILabel with todays date i.e. "29/04/12" 2) At midnight I want that label to update by itself to "30/04/12" without needing to change view or press anything.
这是我不知道该怎么做的第 2 步.我知道如何完成它,例如可能会收到日期更改的系统通知(如果可能的话)或使用某种计时器作为触发器.
It's step 2 that I don't know how to do. I have idea's of how it would be done such as potentially getting a system notification of the date change (if this is even possible) or using some sort of timer as a trigger.
任何帮助将不胜感激,提前致谢.
Any help would be greatly appreciated, thanks in advance.
推荐答案
如果您只想在午夜到来时收到通知(或其他几种情况),那么您可以覆盖 UIApplicationDelegate 的 - (void)applicationSignificantTimeChange:(UIApplication *)application
方法,以便它导致您的标签更新.当然,您还需要在应用程序重新进入前台时更新标签,因为如果日期更改时您的应用程序在后台,则不会调用此方法.
If you are only interested in being notified when midnight arrives (or a couple other cases), then you can override UIApplicationDelegate's - (void)applicationSignificantTimeChange:(UIApplication *)application
method so that it causes your labels to update. Of course, you'll also want to update the labels whenever the application re-enters the foreground, since this method won't be called if your app is in the background when the date changes.
这篇关于一旦iOS中的系统日期更改,如何更改带有日期的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!