iphone - updating UILabel from appDelegate -


i have been having issue last couple of hours , did search unfortunately, didnt find resolves issue.... scenario: have countdowntimer in timerviewcontroller, nstimer , other methods set in appdelegate suppose update timerviewcontroller's label... per label's setter, i'm getting value correctly , showing in nslog however, label not updating on screen... setter being called appdelegate every second , label suppose show timer,

- (void)setmaintimerlabel:(uilabel *)maintimerlabel    {     _maintimerlabel = maintimerlabel;     nslog(@"valueupdated %@",_maintimerlabel);    } 

i have double checked label, hooked interface correctly, tried update label viewdidload test string, label showing me string... please!

edit: appdelegate code:

appdelegate.h

@property (nonatomic, strong) timerviewcontroller *timervc;  - (void)firetimer; 

appdelegate.m

- (void)firetimer {     self.timer = [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(countdowntimer) userinfo:nil repeats:yes]; }  - (void) countdowntimer {     .......    timervc = [[timerviewcontroller alloc]init];     self.timervc.maintimerlabel = [nsstring stringwithformat:@"%02d:%02d:%02d",hours,minutes,seconds];     ....... } 

i resolved issue following below code jabobadilla

i solved performing method go , retrieve value nstimer updating in appdelegate, since method firing nstimer no longer in main thread when leave view , come it. method loop long nstimer valid. placed delay, allowing ui update value, , perform method again. here code in case helps running similar issue. got idea suggestion provided chandan, thanks!!

appdelegate.h

@interface appdelegate : uiresponder <uiapplicationdelegate> {  }  @property (nonatomic, retain) nstimer *countdowntimer; @property (nonatomic, retain) nsstring *timestring; 

countdowntimerviewcontroller.h

@interface countdowntimerviewcontroller : uiviewcontroller {  appdelegate *appdelegate;  }  @property (strong, nonatomic) iboutlet uilabel *labelcountdowntimer;  @property (strong, nonatomic) iboutlet uibutton *buttonstarttimer; @property (strong, nonatomic) iboutlet uibutton *buttonstoptimer;  - (ibaction)starttimer:(id)sender; - (ibaction)stoptimer:(id)sender; 

countdowntimerviewcontroller.m

@implementation countdowntimerviewcontroller  @synthesize labelcountdowntimer;  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil {     self = [super initwithnibname:nibnameornil bundle:nibbundleornil];     if (self) {         // custom initialization     }     return self; }  - (void)viewdidload {     [super viewdidload];         // additional setup after loading view.      //instatiating appdelegate     if(!appdelegate)         appdelegate = (appdelegate *)[[uiapplication sharedapplication] delegate];  }  - (void) viewdidappear:(bool)animated {      if ([appdelegate.countdowntimer isvalid]) {         [self updatelabel];     } else {         labelcountdowntimer.text = @"00:00:00";     }  }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  #pragma mark - button action methods  - (ibaction)starttimer:(id)sender {      [self updatecounter];  }  - (ibaction)stoptimer:(id)sender {      [appdelegate.countdowntimer invalidate];     labelcountdowntimer.text = @"00:00:00";  }  int countlimit=30; //seconds nsdate *startdate;  - (void)updatecounter {      labelcountdowntimer.text = @"00:00:00";     startdate = [nsdate date];      appdelegate.countdowntimer = [nstimer scheduledtimerwithtimeinterval:1.0/10.0                                                                   target:self                                                                 selector:@selector(countdown)                                                                 userinfo:nil                                                                  repeats:yes];  }    - (void)countdown {      if([[nsdate date] timeintervalsincedate:startdate] >= countlimit) {         [appdelegate.countdowntimer invalidate];         return;     }     else {                 nsdate *currentdate = [nsdate date];     nstimeinterval timeinterval = -([currentdate timeintervalsincedate:startdate]);     nsdate *timerdate = [nsdate datewithtimeintervalsince1970:timeinterval];     nsdateformatter *dateformatter = [[nsdateformatter alloc] init];     [dateformatter setdateformat:@"mm:ss"];     [dateformatter settimezone:[nstimezone timezoneforsecondsfromgmt:0.0]];     appdelegate.timestring = [dateformatter stringfromdate:timerdate];     labelcountdowntimer.text = appdelegate.timestring;     }  }    - (void) updatelabel {      if ([appdelegate.countdowntimer isvalid]) {         labelcountdowntimer.text = appdelegate.timestring;         [self performselector:@selector(updatelabel) withobject:nil afterdelay:0.05];     }   } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -