How would you go about implementing a “dayDidChange” method, while avoiding the use of NSTimer?

How would you go about implementing a "dayDidChange" method?

I have a dateLabel, that needs updating, when the day changes.

I already had 2 solutions implemented. But gave up on them.

1st, on viewWillAppear, I would set my label. Chances for date changing when the user is viewing the VC are VERY small ... and it wouldn't really introduce any "errors" to execution But still, it's not perfect.

2nd, I also implemented an NSTimer with intervals of 1 second. Works great. But I'm not too found of the idea of having a method being called if there is a chance that I don't need to do it.

Are there any other options? I need to update that label, when the day changes. Also, is it possible to use NSNotificationCenter with this?

Answers


You can calculate the time left on the day and set a timer to it. You can also listen to UIApplicationSignificantTimeChangeNotification. Note that this notification will be fired not only when the date changes, but for timezone adjustments and other changes. Keep in mind also that the firing of the notification will be triggered only if your app is not in an inactive state.


In your appliciation delegate, implement the following method: -(void)applicationSignificantTimeChange:(UIApplication *)application

This method is called when the day changes, or if the device's time has been changed in the background for whatever reason (such as changes to time zone).

hope it helps. happy coding :)


Need Your Help

Is it possible to replace one marker using gmaps4rails?

ruby-on-rails ruby-on-rails-3 gmaps4rails

Using Gmaps.map.replaceMarkers() I can replace entire marker set. But in my application I will use more than 3000 markers.

How to implement a faster condition checking function? python

python c++ list dictionary cython

I have a small script that wants to extract some unique words based on several conditions and checking through the conditions is taking super long.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.