iphone - NSTimer does not work properly -


i'm pretty new ios development can me! i'm using xcode5-dp4 right , code isn't working (although worked fine before). there countdown 2:00 (min:sec) starting tapping button:

firstviewcontroller.h:

@interface firstviewcontroller : uiviewcontroller {      iboutlet uilabel *countdownlabel;      iboutlet uibutton *countdownstart;      nstimer *countdowntimer;      int secondscount; }  -(ibaction)alert; -(void)delay; 

firstviewcontroller.m:

uialertview *alert;  -(void)delay {     [alert show];  }    -(ibaction)alert{      alert = [[uialertview alloc]           initwithtitle:@"die zeit ist um!"           message:@"du darfst das zähneputzen nun beenden, aber vergiss nicht, noch mehr für deine mundhygiene zu tun."           delegate:self           cancelbuttontitle:@"ok"           otherbuttontitles:nil];       [self performselector:@selector(delay) withobject:nil afterdelay:120.0];  }    - (ibaction)zaehneputzen:(id)sender {      [self settimer];  }    - (void) settimer {      secondscount = 120;     countdowntimer = [nstimer scheduledtimerwithtimeinterval:(1.0) target:(self) selector:@selector(timerrun) userinfo:(nil)     repeats:(yes)];  }   - (void) timerrun {      secondscount = secondscount-1;     int minutes = secondscount / 60;     int seconds = secondscount - (minutes * 60);      nsstring *timeroutput = [nsstring stringwithformat:@"%02d:%02d", minutes, seconds];     countdownlabel.text = timeroutput;      if(secondscount == 0){         [countdowntimer invalidate];        countdowntimer = nil;      } } 

the problems: - timer counting fast , not use full seconds (the label changing after 0.5sec , after 1.5sec , on...) - timer keeps on counting negative range...

i hope can me =).

thanks in advance, andrea!

nstimer doesn't work given time interval. so, found 1 solution put below line code after nstimer object

[[nsrunloop currentrunloop] addtimer:yourtimer formode:nsrunloopcommonmodes]; 

this may solve problem.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -