I need to start NSTimer by 0:0:0 that I am doing and I have a Pause button on click of that the timer has to pause after some time if a user clicks play it has to run from paused value of time. How can I pause and play in NSTimer? Any help? Thanks in advance.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
Updated answer for Swift 2
Use following code to start timer with arguments also:
and then use
to stop the timer.
I hope this code will help you.
Thanks.
Try this shizzle... worked great for me
EDIT
To be honest my actual code is this:
I used a UIButton and used this code when clicked.
remember to put this:
in your .h file
EDIT!
here is the countUp method. forget the down method. seconds, minutes, hours are Ints
there is no such thing as pause for NSTimer, you have to stop and start it again.
[yourTimer invalidate]; //will stop the timer after which you can start it again
refreshTimer
should be on class level. Use the following code to stop the timer:To start you can again schedule timer as Line 3
You don’t. Instead of pausing simply invalidate and release the old timer and when the users presses Play again, create a fresh timer.