iphone - How to Pause/Play NSTimer? -
i need start nstimer 0:0:0 doing , have pause button on click of timer has pause after time if user clicks play has run paused value of time. how can pause , play in nstimer? help? in advance.
try shizzle... worked great me
edit
to honest actual code this:
-(ibaction)clicked:(id)sender { if ([startstop.titlelabel.text isequaltostring:@"start"]) { [startstop settitle:@"pause" forstate:uicontrolstatenormal]; [startstop settitlecolor:[uicolor redcolor] forstate:uicontrolstatenormal]; timer = [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(countup) userinfo:nil repeats:yes]; timerdown = [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(countdown) userinfo:nil repeats:yes]; } else if ([startstop.titlelabel.text isequaltostring:@"pause"]) { [startstop settitle:@"resume" forstate:uicontrolstatenormal]; [startstop settitlecolor:[uicolor colorwithred:0/255 green:0/255 blue:255/255 alpha:1.0] forstate:uicontrolstatenormal]; pausestart = [[nsdate datewithtimeintervalsincenow:0] retain]; previousfiredate = [[timer firedate] retain]; [timer setfiredate:[nsdate distantfuture]]; } else if ([startstop.titlelabel.text isequaltostring:@"resume"]) { [startstop settitle:@"pause" forstate:uicontrolstatenormal]; [startstop settitlecolor:[uicolor redcolor] forstate:uicontrolstatenormal]; float pausetime = -1*[pausestart timeintervalsincenow]; [timer setfiredate:[nsdate datewithtimeinterval:pausetime sincedate:previousfiredate]]; [pausestart release]; [previousfiredate release]; } } i used uibutton , used code when clicked.
remember put this:
nsdate *pausestart, *previousfiredate; in .h file
edit!
here countup method. forget down method. seconds, minutes, hours ints
- (void)countup { seconds += 1; if (seconds == 60) { seconds = 0; minutes++; if (minutes == 60) { minutes = 0; hours++; } } }
Comments
Post a Comment