Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

like image 237
msec Avatar asked Apr 29 '12 03:04

msec


1 Answers

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.

like image 70
UIAdam Avatar answered Sep 30 '22 18:09

UIAdam