How can I change a label with a date once the system date changes in iOS?

99封情书 提交于 2019-12-23 09:59:33

问题


I have a simple query but don't know how to do it.

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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/10369416/how-can-i-change-a-label-with-a-date-once-the-system-date-changes-in-ios

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