objective c - Replacing NSString with new string not working -
i'm trying replace string every sec using timer update value. can replace nsstring pretty doing
mystring = [cclabelttf labelwithstring:varyingparameterlabelstring fontname:@"helvetica" fontsize:14];
for example, reason won't update nsstring's value. below i'm trying do.
@implementation grid { nstimer *timeremainingtimer; cclabelttf *_varyingparameterlabelvalue; } -(void)setuplabels{ int timeremaining = 30; varyingparameterlabelvaluestring = [nsstring stringwithformat:@"%i", timeremaining]; timeremainingtimer = [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(decreasetimeremaining) userinfo:nil repeats:true]; _varyingparameterlabelvalue = [cclabelttf labelwithstring:varyingparameterlabelvaluestring fontname:@"helvetica" fontsize:20]; [self addchild:_varyingparameterlabelvalue]; } -(void)decreasetimeremaining{ timeremaining--; nsstring *timeremainingstring = [nsstring stringwithformat:@"%i", timeremaining]; _varyingparameterlabelvalue = [cclabelttf labelwithstring:@"timeremainingstring" fontname:@"helvetica" fontsize:20]; //still reads 30 after runs }
if literally re-create , paste lastly line of timer method setuplabels method, changes string normal, within of timer method doesn't anything. have logged create sure timer running, , is. help!
in decreasetimeremaining
create local variable called timeremainingstring
, never utilize update label. also, creating whole new label instead of updating existing one.
-(void)decreasetimeremaining{ timeremaining--; nsstring *timeremainingstring = [nsstring stringwithformat:@"%i", timeremaining]; [_varyingparameterlabelvalue setstring:timeremainingstring]; }
objective-c cocos2d-iphone cocos2d-iphone-3
No comments:
Post a Comment