ios - NSTimer : Update Label after switch View doesn't work -
i want utilize nstimer countdown. counter works fine;-)! i switch viewcontroller timer doesn't runs in "foreground" - label isn't updated.... after coming view.
my nslog shows timer still runnig, want ;-)
so in whicht way have work, timer update label?
here code:
- (ibaction)startclock:(id)sender { globaltimer = 20; timer = [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(updatecircularprogressbar) userinfo:nil repeats:yes]; } - (void)updatecircularprogressbar { // values passed on circular progress bar if (globaltimer > 0 && globaltimer <= 1200) { globaltimer--; minutesleft = globaltimer / 60; secondsleft = globaltimer % 60; [self drawcircularprogressbarwithminutesleft:minutesleft secondsleft:secondsleft]; nslog(@"time left: %02d:%02d", minutesleft, secondsleft); } else { [self drawcircularprogressbarwithminutesleft:0 secondsleft:0]; [timer invalidate]; } } i tested run "updatecircularprogressbar" in viewdidload shows no result... thx help update more more code:
/*-------------------- timer --------------------*/ // draws progress circles on top of painted background - (void)drawcircularprogressbarwithminutesleft:(nsinteger)minutes secondsleft:(nsinteger)seconds { // removing unused view prevent them stacking (id subview in [self.view subviews]) { if ([subview iskindofclass:[circularprogresstimer class]]) { [subview removefromsuperview]; } } // init our view , set current circular progress bar value cgrect progressbarframe = cgrectmake(0, 0, 180, 180); progresstimerview = [[circularprogresstimer alloc] initwithframe:progressbarframe]; [progresstimerview setcenter:cgpointmake(160, 210)]; [progresstimerview setpercent:seconds]; if (minutes == 0 && seconds <= 0) { [progresstimerview setinstancecolor:[uicolor magentacolor]]; } // here, setting minutes left before adding parent view [progresstimerview setminutesleft:minutesleft]; [progresstimerview setsecondsleft:secondsleft]; [self.view addsubview:progresstimerview]; progresstimerview = nil; } the label in file (circularprogresstimer) controls progessbar...
ios objective-c label progress-bar nstimer
No comments:
Post a Comment