I develop Stop Watch Application.
In my application, there are Two UIButtons , StartBtn
and StopBtn
, And also I use NSTimer
.
Now, i want to start NSTimer
when user click on StartBtn
and also stop when your click on StopBtn
.
I know that NSTimer
is stopped by [MyTimerName invalidate];
method but I don't know how to start NSTimer
again?
The
NSTimer
class is a bit awkward to use; rather than separating the creation/destruction from the start/stop, it's all rolled together. In other words the timer starts as soon as it's created and stops as soon as it's destroyed.You therefore need to use the existence of the
NSTimer
object as a flag to indicate if it's running; something like this:You could always use fire to start a NStimer again
To stop it:
You can start the timer through
Then the delegate function:
And to stop Timer