iphone - TimeInterval function setting with UIPicker -


i have following part of code. executing when user select time interval uipicker.

if([[arrayno objectatindex:row] isequaltostring:@"1 minutes"])     time=60;  if([[arrayno objectatindex:row] isequaltostring:@"5 minutes"])     time=300;  [nstimer scheduledtimerwithtimeinterval:60 target:self selector:@selector(updatemethod) userinfo:nil repeats:yes]; 

i defining 2 time in uipicker "1 minutes" , "5 minutes". suppose once user select "1 minutes" function "updatemethod" call after 1 minutes of time period. let suppose user again change time "5 mnutes" uipicker. happen? timer set "5 minutes" or set "1 minutes" , "5 minutes" both?

how design code set function calling 1 time only? me in concept?

every time called, schedule new timer, in example, both.

i discourage scheduledtimerwithtimeinterval:... reason. have no way cancel timer. should create nstimer* ivar this:

@interface ... { } @property (nonatomic, readwrite, retain) nstimer *updatetimer; @end  @implementation ... @synthesize updatetimer=updatetimer_;  - (void)setupdatetimer:(nstimer *)atimer {   if (atimer != updatetimer_) {     [atimer retain];     [updatetimer_ invalidate];     [updatetimer_ release];     updatetimer_ = atimer;   } } ... self.timer = [nstimer timerwithtimenterval:60 target:self selector:@selector(updatemethod) userinfo:nil repeats:yes]; 

this automatically clear old timer whenever set new timer.

do note basing logic on ui strings (@"1 minutes") break localization if ever want translated other languages. instead, either use row decide value, or add small dictionaries or objects arrayno hold label , value.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -