View Full Version : Timer app
arnieterm
Jan 28, 2009, 07:56 AM
In a navigation controller based iphone app with two view controllers. I have to make use of a timer. That timer should be accessible from both view controllers. Should this timer be created in app delegate so that both view controllers can access it
The first view controller takes some entries in text fields and starts a timer based on these. The next view controller shows the time elapsed since the start of the timer. This means the UILabel on 2nd view controller needs to be updated after some pre-defined time interval based on entries from first controller.
Can we use NSTimer for iphone? If not then what other option can be used?
Thanks
Arnieterm
dejo
Jan 28, 2009, 09:22 AM
Can we use NSTimer for iphone? If not then what other option can be used?
Yes, you can use NSTimer, as demonstrated in the BonjourWeb, HeadsUpUI, SpeakHere, TableViewSuite and WiTap sample apps.
Either add it to the appDelegate or create a new class that both viewControllers can access.
arnieterm
Feb 2, 2009, 09:32 AM
I have created an NSTimer within my view controller that has labels for updating the hour, minute and seconds. I need to repeat the timer after every 1 second as the app is similar to stop watch. Should I use NSDate or Hours, Minutes, Seconds [NSInteger] for handling the time as I am looking for performance viewpoint also. When
Also I need to pause the NSTimer at the click of a button and then to resume it at another click from where it last starts. I see using invalidate will stop the timer, right?
jnic
Feb 2, 2009, 09:38 AM
I have created an NSTimer within my view controller that has labels for updating the hour, minute and seconds. I need to repeat the timer after every 1 second as the app is similar to stop watch. Should I use NSDate or Hours, Minutes, Seconds [NSInteger] for handling the time as I am looking for performance viewpoint also. When
One second is long enough that performance won't be an issue, so use whatever you're most comfortable with.
Also I need to pause the NSTimer at the click of a button and then to resume it at another click from where it last starts. I see using invalidate will stop the timer, right?
Right. Class ref here (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html).
arnieterm
Feb 3, 2009, 03:03 AM
NSTimer's invalidate method is stopping the timer from executing but I am looking for a way to temprarily pausing at a click of a button. Then I want to resume the timer at the click of another button
WhiteRabbit
Feb 22, 2009, 11:28 PM
NSTimer's invalidate method is stopping the timer from executing but I am looking for a way to temprarily pausing at a click of a button. Then I want to resume the timer at the click of another button
I belive you could use the fireDate method of NSTimer to extract the fire date to an NSTimeInterval object using timeIntervalSinceNow. Then use set setFireDate on your timer to pause your timer with [NSDate distantFuture] (your timer will keep going, but to an indefinite future time).
Finally, to resume, use setFireDate on your timer object once again, passing it your recently created NSTimeInterval object.
firewood
Feb 23, 2009, 05:24 AM
You could just leave the timer running, check a pause flag inside the time handler, and not draw when paused.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.